How to fix Error: listen EADDRINUSE while using nodejs?
What really helped for me was:
killall -9 node
But this will kill a system process.
With
ps ax
you can check if it worked.
EADDRINUSE
means that the port number which listen()
tries to bind the server to is already in use.
So, in your case, there must be running a server on port 80 already.
If you have another webserver running on this port you have to put node.js behind that server and proxy it through it.
You should check for the listening
event like this, to see if the server is really listening:
var http=require('http');
var server=http.createServer(function(req,res){
res.end('test');
});
server.on('listening',function(){
console.log('ok, server is running');
});
server.listen(80);