在Node.js中侦听EADDRNOTAVAIL错误 [英] listen EADDRNOTAVAIL error in Node.js
问题描述
我在服务器中安装了Nginx和Node.js.
I installed Nginx and Node.js in my server.
当我尝试运行我的node.js文件时,出现错误:
When I try run my node.js file, I get an error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:614:11)
at Array.0 (net.js:689:28)
at EventEmitter._tickCallback (node.js:192:40)
如何我可以解决这个问题吗?
How can I fix this problem?
谢谢!
推荐答案
我有这个问题,我认为这是一个端口问题,但结果却是 IP 问题。
I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.
我的 HOST
环境变量指向静态IP,我的节点服务器正在侦听该地址。在我的路由器回收的某个时刻,它开始为我的机器分配一个新IP,我开始收到你发布的错误。它是通过更改我的服务器正在收听的地址来修复的。
I had my HOST
environmental variable pointing to a static IP, and my Node server was listening to that address. At some point when my router recycled, it started assigning my machine a new IP, and I started getting the error you posted. It was fixed by changing the address my server was listening to.
我的配置:
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
http.createServer(app).listen(app.get('port'), app.get('host'), function(){
console.log("Express server listening on port " + app.get('port'));
});
确保您的主机正在点击您的计算机。在任何情况下,@ miltonb建议的环回应始终有效:
Make sure your host is hitting your machine. In any case, the loopback, as @miltonb suggested, should always work:
app.set('host', '127.0.0.1');
这篇关于在Node.js中侦听EADDRNOTAVAIL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!