即使本地主机存在于/ etc / hosts(MacOS El Capitan)中,我也会在运行简单节点服务器时获得`getAddrInfo ENOTFOUND localhost`

设置和运行普通节点js服务器时,发生了一件非常奇怪的事情。

当我运行node server.js ,我得到以下错误:

 Server running at http://localhost:1337/ events.js:160 throw er; // Unhandled 'error' event ^ Error: getaddrinfo ENOTFOUND localhost at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) 

当我在浏览器中打开http://localhost:1337/时,表示page does not exist

当我运行sudo node server.js ,它运行正常,没有任何错误,我可以访问我的网站在https://localhost:1337

这是我的/ etc / hosts文件:

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

我的server.js:

 // Require what we need var http = require("http"); // Build the server var app = http.createServer(function(request, response { response.writeHead(200, { "Content-Type": "text/plain" }); response.end("Hello world!\n"); }); // Start that server, baby app.listen(1337, "localhost"); console.log("Server running at http://localhost:1337/"); 

其他详情

  1. 操作系统:Mac OS(El Capitan)
  2. Node JS版本:6.10.3(全局安装)
  3. NPM版本:4.5.0(全球安装)

以下是我的问题

  1. 为什么上面的server.js文件使用pipe理员权限而不是普通用户?
  2. 全局安装的节点只能使用pipe理员权限吗?
  3. Mac OS上还有什么可以影响除/ etc / hosts之外的DNS查询? 我已经刷新了我的DNScaching并重新启动我的操作系统,以确保旧的DNS查找没有被使用。