listen EADDRNOTAVAIL error in Node.js

前端 未结 11 732
陌清茗
陌清茗 2020-11-27 15:43

I installed Nginx and Node.js in my server.

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

node.js:201
        throw e; // process.nextTick error, or \'e         


        
相关标签:
11条回答
  • 2020-11-27 16:26

    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.

    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:

    var http = require('http');
    http.createServer( function ).listen(8000, '127.0.0.1');
    
    0 讨论(0)
  • 2020-11-27 16:30

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

    0 讨论(0)
  • 2020-11-27 16:31

    For me, the issue was that the IP that I wrote simply didn't exists :) usually at home I have a 192.168.x.x IP, and after a restart I had a different address ... when I tried to gulp serve my app - it had a config with the old IP ....

    as always 127.0.0.1 will work, but when you want to verify your website with other devices, you want to use the external IP 192.168.x.x ... or similar.

    0 讨论(0)
  • 2020-11-27 16:33

    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

    0 讨论(0)
  • 2020-11-27 16:34

    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 and still busy adding the new ipv6 address.

    Using an execSync [see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options] to call 'sleep' for a 2 second pause seems to allow listen to not error with Error: listen 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.]

    0 讨论(0)
提交回复
热议问题