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 t
This works for me (I'm using mac). Run this command
lsof -PiTCP -sTCP:LISTEN
This's going to display a list of ports that your syetem is using. Find the PID
that your node is running
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 17269 hientrq 16u IPv6 0xc42959c6fa30c3b9 0t0 TCP *:51524 (LISTEN)
node 17269 hientrq 19u IPv4 0xc42959c71ae86fc1 0t0 TCP localhost:1337 (LISTEN)
and run kill -9 [YOUR_PID]
EADDRINUSE means port of your nodejs app is already in use.
lsof -i tcp:3000
kill -9 processId
For windows users execute the following command in PowerShell window to kill all the node processes.
Stop-Process -processname node
EADDRINUSE
means that the port(which we try to listen in node application) is already being used. In order to overcome, we need to identify which process is running with that port.
For example if we are trying to listen our node application in 3000 port. We need to check whether that port is already is being used by any other process.
$sudo netstat -plunt |grep :3000
That the above command gives below result.
tcp6 0 0 :::3000 :::* LISTEN 25315/node
Now you got process ID(25315), Kill that process.
kill -9 25315
npm run start
Note: This solution for linux users.
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);
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
# LOGIC
CHROME_PIDS=`pidof chrome`
PORT_PIDS=`lsof -t -i tcp:1337`
for pid in $PORT_PIDS
do
if [[ ${CHROME_PIDS} != *$pid* ]];then
# NOT FOUND IN CHROME PIDS
echo "Killing $pid..."
ps -p "$pid"
kill -kill "$pid"
fi
done
sails lift
# OR 'node app' OR whatever that starts your node
exit