在Node.js中侦听EADDRNOTAVAIL错误

时间:2021-09-19 18:30:12

I installed Nginx and Node.js in my server.

我在我的服务器上安装了Nginx和Node.js.

When I try run my node.js file, I get an error:

当我尝试运行我的node.js文件时,出现错误:

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?

我该如何解决这个问题?

Thanks!

谢谢!

9 个解决方案

#1


42  

I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.

我有这个问题,我认为这是一个端口问题,但事实证明这是一个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.

我的HOST环境变量指向一个静态IP,我的Node服务器正在监听该地址。在我的路由器回收的某个时刻,它开始为我的机器分配一个新IP,我开始收到你发布的错误。它是通过更改我的服务器正在侦听的地址来修复的。

My config:

我的配置:

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'));
});

Make sure your host is hitting your machine. In any case, the loopback, as @miltonb suggested, should always work:

确保您的主机正在击中您的计算机。在任何情况下,@ miltonb建议的环回应始终有效:

app.set('host', '127.0.0.1');

#2


6  

I was getting the same error, and then I changed the port and worked

我得到了同样的错误,然后我改变了端口并且工作了

#3


4  

I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.

我认为你需要更多的上下文,比如你的一些代码。我猜你开始在网络服务器或套接字上听?基于这个假设,当我在测试服务器上运行基本Web服务器时,我会得到类似的东西,除非我使用localhost运行。

events.js:48
        throw arguments[1]; // Unhandled 'error' event
                   ^
Error: listen EADDRNOTAVAIL
    at errnoException (net.js:670:11)
    at Array.0 (net.js:756:28)
    at EventEmitter._tickCallback (node.js:190:38)

Try changing the [hostname] parameter to localhost:

尝试将[hostname]参数更改为localhost:

var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');

#4


4  

Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.

可能是该节点已在运行服务器吗?我收到了类似的错误,并在排除故障时发现了关闭上一个节点服务器解决了我的问题。

#5


1  

Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error

大多数情况下,它将是IP地址或主机名。原因是,节点js将其作为启动服务器的关键项。如果存在冲突或错误的IP地址,则会出现此错误

Error: listen EADDRNOTAVAIL

错误:听EADDRNOTAVAIL

hope this helps.

希望这可以帮助。

#6


1  

For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0

对我来说,我有同样的错误,当我检查我的配置时,我发现host = 127.0.0.0会引发错误,因为它应该是127.0.0.1而不是127.0.0.0

#7


0  

var express = require('express');

var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');

app.listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});

works for me.
it also generic for debug by localhost and your local ip without any changes.

适合我。它也是localhost和你的本地ip调试的通用版,没有任何变化。

#8


0  

This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen still adding the new ipv6 address.

这也会发生在'ip addr add i:p:v:6'仍然处于不稳定状态或刚刚执行的时候(刚刚执行/ ing),接口是我认为还没准备好继续监听仍然添加新的ipv6地址。

A execSync sleep for 2 seconds seems to allow listen to not error with Error: listen EADDRNOTAVAIL.

一个execSync睡眠2秒似乎允许听错误错误:听EADDRNOTAVAIL。

It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.

这是我在Ubuntu上的NodeJS 7.4.0中的一个错误,因为在使用/监听连接之前的瞬间创建ipv4地址不会发生这种情况。

#9


-1  

In my case, I fixed it by checking the directory /tasks/options

就我而言,我通过检查目录/ tasks / options来修复它

I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.

我发现connect.js文件的静态IP地址不正确。我只是把它改成了正确的它并且它起作用了。

#1


42  

I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.

我有这个问题,我认为这是一个端口问题,但事实证明这是一个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.

我的HOST环境变量指向一个静态IP,我的Node服务器正在监听该地址。在我的路由器回收的某个时刻,它开始为我的机器分配一个新IP,我开始收到你发布的错误。它是通过更改我的服务器正在侦听的地址来修复的。

My config:

我的配置:

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'));
});

Make sure your host is hitting your machine. In any case, the loopback, as @miltonb suggested, should always work:

确保您的主机正在击中您的计算机。在任何情况下,@ miltonb建议的环回应始终有效:

app.set('host', '127.0.0.1');

#2


6  

I was getting the same error, and then I changed the port and worked

我得到了同样的错误,然后我改变了端口并且工作了

#3


4  

I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.

我认为你需要更多的上下文,比如你的一些代码。我猜你开始在网络服务器或套接字上听?基于这个假设,当我在测试服务器上运行基本Web服务器时,我会得到类似的东西,除非我使用localhost运行。

events.js:48
        throw arguments[1]; // Unhandled 'error' event
                   ^
Error: listen EADDRNOTAVAIL
    at errnoException (net.js:670:11)
    at Array.0 (net.js:756:28)
    at EventEmitter._tickCallback (node.js:190:38)

Try changing the [hostname] parameter to localhost:

尝试将[hostname]参数更改为localhost:

var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');

#4


4  

Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.

可能是该节点已在运行服务器吗?我收到了类似的错误,并在排除故障时发现了关闭上一个节点服务器解决了我的问题。

#5


1  

Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error

大多数情况下,它将是IP地址或主机名。原因是,节点js将其作为启动服务器的关键项。如果存在冲突或错误的IP地址,则会出现此错误

Error: listen EADDRNOTAVAIL

错误:听EADDRNOTAVAIL

hope this helps.

希望这可以帮助。

#6


1  

For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0

对我来说,我有同样的错误,当我检查我的配置时,我发现host = 127.0.0.0会引发错误,因为它应该是127.0.0.1而不是127.0.0.0

#7


0  

var express = require('express');

var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');

app.listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});

works for me.
it also generic for debug by localhost and your local ip without any changes.

适合我。它也是localhost和你的本地ip调试的通用版,没有任何变化。

#8


0  

This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen still adding the new ipv6 address.

这也会发生在'ip addr add i:p:v:6'仍然处于不稳定状态或刚刚执行的时候(刚刚执行/ ing),接口是我认为还没准备好继续监听仍然添加新的ipv6地址。

A execSync sleep for 2 seconds seems to allow listen to not error with Error: listen EADDRNOTAVAIL.

一个execSync睡眠2秒似乎允许听错误错误:听EADDRNOTAVAIL。

It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.

这是我在Ubuntu上的NodeJS 7.4.0中的一个错误,因为在使用/监听连接之前的瞬间创建ipv4地址不会发生这种情况。

#9


-1  

In my case, I fixed it by checking the directory /tasks/options

就我而言,我通过检查目录/ tasks / options来修复它

I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.

我发现connect.js文件的静态IP地址不正确。我只是把它改成了正确的它并且它起作用了。