listen EADDRNOTAVAIL error in Node.js


Question

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 '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!

1
36
5/30/2012 5:33:59 AM

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

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.

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:

app.set('host', '127.0.0.1');
49
8/31/2013 2:27:02 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon