If I run a server with the port 80, and I try to use xmlHTTPrequest i get 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();
While killing the NODE_PORT, it might kill your chrome process or anything that is listening to the same port, and that's annoying.
This shell script may be helpful - in my case the port is 1337 but you can change it anytime
I had the same issue recently.
It means that the port is already being used by another application (express or other software)
In my case, I had accidentally run express on 2 terminals, so exiting the terminal using 'Ctrl + C' fixed things for me. (Run server from only one terminal)
Hope it helps others.
Another thing that can give this error, is two HTTP servers in the same node code. I was updating some Express 2 to Express 3 code, and had this...
And, it triggered this error.
For other people on windows 10 with node as
localhost
and running on a port like 3500, not 80 ...What does not work:
What shows information but still not does work:
What does work:
Git Bash or Powershell on Windows
Notice the PID ( far right )
I could not get
killall
to work... soNow after that not so fun exercise on windows, I realized I can use task manager and find the Node engine and just end it.
FYI , I was using Visual Studio Code to run Node on port 3500, and I use Git Bash shell inside VS code. I had exited gracefully with Ctrl + C , but sometimes this does not kill it. I don't want to change my port or reboot so this worked. Hopefully it helps others. Otherwise it is documentation for myself.
You should try killing the process that is listening on port 80.
Killall will kill all the node apps running. You might not want to do that. With this command you can kill only the one app that is listening on a known port.
If using unix try this command:
In my case Apache HTTP Server was run on port 80 I solved it by issue the command as root
sudo killall httpd
Update
If Jenkin is installed and running on your Mac;
sudo lsof -i tcp:8080
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist