node.js中的IP地址有什么问题?
var http = require('http'); http.createServer(function(request,response){ response.writeHead(200,{"Content-Type":"text/plain"}); response.write("Hello, world!"); response.end(); }).listen(8888,'127.0.0.2');
但是,当我运行node test.js
我得到了
events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EADDRNOTAVAIL at errnoException (net.js:901:11) at Server._listen2 (net.js:1020:19) at listen (net.js:1061:10) at net.js:1143:9 at dns.js:72:18 at process._tickCallback (node.js:415:13) at Function.Module.runMain (module.js:499:11) at startup (node.js:119:16) at node.js:902:3
它在127.0.0.1
下工作正常,或者完全不指定IP地址。 任何人都可以解释为什么错误发生,我应该如何正确指定一个地址?
要使用这个地址,你必须在你的系统上configuration一个接口。 您的环回接口configuration为127.0.0.1。