i am testing a server written in nodejs on windows 7 and when i try to run the tester in the command line i get the following error
Error: listen EADDRINUSE
The aforementioned killall -9
node, suggested by Patrick works as expected and solves the problem but you may want to read the edit part of this very answer about why kill -9
may not be the best way to do it.
On top of that you might want to target a single process rather than blindly killing all active processes.
In that case, first get the process ID (PID) of the process running on that port (say 8888):
lsof -i tcp:8888
This will return something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 57385 You 11u IPv6 0xac745b2749fd2be3 0t0 TCP *:ddi-tcp-1
(LISTEN) Then just do (ps - actually do not. Please keep reading below):
kill -9 57385
I have solved this issue by adding below in my package.json for killing active PORT - 4000 (in my case) Running on WSL2/Linux/Mac
"scripts": {
"dev": "nodemon app.js",
"predev":"fuser -k 4000/tcp && echo 'Terminated' || echo 'Nothing was running on the PORT'",
}
Source
One possible solution that worked for me was simply to close the window in browser where I had the corresponding "http://localhost:3000/" script running.
To anyone who has tried all of the above, but still can't find the rouge process, try them all again but make sure you include "sudo" in front of the commands.
In window, please execute this command:
taskkill /F /PID 1952
If you like UI more, find the process Node.js in windows task manager and kill it.