Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Error: listen EADDRINUSE while using NodeJS?

If I run a server with the port 80, and I try to use XMLHttpRequest I am getting this error: Error: listen EADDRINUSE

Why is it problem for NodeJS, if I want to do a request, while I run a server on the port 80? For the webbrowsers it is not a problem: I can surf on the internet, while the server is running.

The server is:

  net.createServer(function (socket) {     socket.name = socket.remoteAddress + ":" + socket.remotePort;     console.log('connection request from: ' + socket.remoteAddress);     socket.destroy();   }).listen(options.port); 

And the request:

var xhr = new XMLHttpRequest();  xhr.onreadystatechange = function() {     sys.puts("State: " + this.readyState);      if (this.readyState == 4) {         sys.puts("Complete.\nBody length: " + this.responseText.length);         sys.puts("Body:\n" + this.responseText);     } };  xhr.open("GET", "http://mywebsite.com"); xhr.send(); 
like image 360
Danny Fox Avatar asked Mar 27 '12 22:03

Danny Fox


People also ask

How do I fix Eaddrinuse error?

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.

What does Eaddrinuse mean?

The error EADDRINUSE means you have multiple instances of your server running or multiple node.

How do I kill all node servers?

process. exit() in your application causes the NodeJS instance to close. killall node in bash would kill all NodeJS instances running on your machine.


1 Answers

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.

like image 106
Patrick Avatar answered Sep 22 '22 04:09

Patrick