emilySmitley emilySmitley - 6 months ago 39
Node.js Question

Node EADDRINUSE on AWS regardless of port

I'm getting so frustrated... I can't find any information online to help me.

My setup is:


  • AWS EC2 instance

  • Nginx pointing to 127.0.0.1:3000

  • Node JS v0.10.32

  • mongoDB process running as daemon



I've tried using my public DNS/public IP and restarting nginx, I've tried port 80, 8000, 1337, etc... I've tried deleting Nginx.
ps aux | grep :3000
returns nothing.
ps aux | grep :80
returns nothing. etc...

Here's the relevant code:

https.createServer(options, app).listen(app.get('port'), '127.0.0.1', function() {
console.log('Express server listening on port ' + app.get('port'));
});
http.createServer(function(req, res) {
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
}).listen(3000);


No matter which port I use, I get the same error for
sudo node app.js
and
node app.js
:


events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at net.js:1146:9
at dns.js:72:18
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3





I did get this to work, but I need to redirect traffic to port 443 and use https:

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

Answer

You can use netstat -tulpn | grep :XX , XX being the port you want to check.

It seems that you're trying to start both a http and a https server on the same port. delete the http.createServer bit and you'll be fine.

Comments