node.js - I am getting `getAddrInfo ENOTFOUND localhost` on running simple node server even though localhost is present in /etc/hosts (MacOS El Capitan) -


i have weird thing happening while setting , running normal node js server.

when run node server.js, following error:

server running @ http://localhost:1337/ events.js:160   throw er; // unhandled 'error' event   ^ error: getaddrinfo enotfound localhost        @ errnoexception (dns.js:28:10)        @ getaddrinforeqwrap.onlookup [as oncomplete] (dns.js:76:26) 

when open http://localhost:1337/ in browser, says page not exist.

when run sudo node server.js, runs fine without error , can access site @ https://localhost:1337

here /etc/hosts file:

127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 

my server.js:

// require need var http = require("http"); // build server var app = http.createserver(function(request, response {     response.writehead(200, {         "content-type": "text/plain"     }); response.end("hello world!\n"); }); // start server, baby app.listen(1337, "localhost"); console.log("server running @ http://localhost:1337/"); 

other details

  1. os: mac os (el capitan)
  2. node js version: 6.10.3 (installed globally)
  3. npm version: 4.5.0 (installed globally)

following questions

  1. why above server.js file working admin access not normal user?
  2. does globally installed node work admin access?
  3. is there else in mac os can affect dns lookup other /etc/hosts? have flushed dns cache , reboot os make sure older dns lookup not being used.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -