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
In below command replace your portNumber
sudo lsof -t -i tcp:portNumber | xargs kill -9
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
I have the same problem too,and I simply close the terminal and open a new terminal and run
node server.js
again. that works for me, some time just need to wait for a few second till it work again.
But this works only on a developer machine instead of a server console..
For other people on windows 10 with node as localhost
and running on a port like 3500, not 80 ...
What does not work:
killall ? command not found
ps -aux | grep 'node' ? ps: user x unknown
What shows information but still not does work:
ps -aef | grep 'node'
ps ax
kill -9 61864
What does work:
Git Bash or Powershell on Windows
net -a -o | grep 3500 (whatever port you are looking for)
Notice the PID ( far right )
I could not get killall
to work... so
Now 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.
Under a controller env, you could use:
pkill node
before running your script should do the job.
Bear in mind this command will kill all the node
processes, which might be right if you have i.e a container running only one instance, our you have such env where you can guarantee that.
In any other scenario, I recommend using a command to kill a certain process id or name you found by looking for it programmatically. like if your process is called, node-server-1 you could do pkill node-server-1
.
This resource might be useful to understand: https://www.thegeekstuff.com/2009/12/4-ways-to-kill-a-process-kill-killall-pkill-xkill/
Try both commands and it will stop all node process.
killall 9 node
pkill node
npm start