Port 3000 is already in use [nodemon] app crashed - waiting for file changes before starting... so please help me to solve this
-
Did you tried to close and reopen terminals? – Jaydip Jadhav Oct 29 '19 at 10:19
-
Try to use other port or kill whatever is running on port 3000. – Nicolae Maties Oct 29 '19 at 10:21
-
The problem seems pretty clear - Something is using port 3000. What have you tried ? – Weedoze Oct 29 '19 at 10:26
-
@JaydipJadhav yes, bro there is no any open terminals – Afeesudheen Nov 03 '19 at 12:13
-
Off topic and should be on serverfault.com but is likely already a duplicate. – JGurtz May 05 '20 at 19:11
6 Answers
Killing a process that owns port 3000
Unix-like Operating Systems (e.g. GNU/Linux, FreeBSD, macOS)
First, let’s take a look at how we can kill a process that has a port open.
Using the lsof
command, we can retrieve the PID that has the given port:
$ lsof -i :3000 -t
12345
Then we can kill this process just by doing:
$ kill 12345
Let’s turn this into a one-liner:
lsof -i :3000 -t | xargs kill
If you’re using environment variable to set the server port, we can specify that instead of hardcoding our values:
lsof -i :${PORT} -t | xargs kill
Lastly, we can default to port 3000 if environment variable isn’t set:
lsof -i :${PORT:-3000} -t | xargs kill
Microsoft Windows
Unless you’re running nodemon on Windows Subsystem for Linux (WSL), lsof
is not available in Windows. However, netstat
is available on Windows shell:
netstat -ano | findstr :3000
This will return the PID of the process that is using up port 3000 which we can use to kill the process using tskill
command:
tskill 12345
If all you care about is making sure the process that owns the port is dead without any graceful shutdown, you can disregard the caveat below.
Caveat on Windows process kill behaviourIf your app listens in on
SIGTERM
to shutdown gracefully when nodemon triggerstskill
command, Windows will unconditionally terminate your process before your app has a chance to fire theprocess.on('SIGTERM')
event handler.More details on this caveat are here:
Sometimes the tskill command won't run due to some reasons. You can also use the following command for killing the process after finding the PID from the above netstat command
taskkill /F /T /PID 12345
Getting nodemon to execute hooks
Nodemon lets you set up event hooks through nodemon.json
configuration file:
{
"events": {
"crash": "sh -c 'lsof -i :${PORT:-3000} -t | xargs kill'"
}
}
This will cause nodemon to execute sh -c 'lsof -i :${PORT:-3000} -t | xargs kill
command whenever your app crashes, thereby killing the child process it spawned that’s keeping the port open.
For more info on nodemon events, checkout their documentation:

- 798
- 8
- 11

- 546
- 3
- 7
-
how to run "events" for windows? please write windows event too. – Mohmmad Ebrahimi Aval Dec 07 '20 at 09:59
-
What does 12345 actually stand for? Is that meaning of the folder name? – sniffingdoggo Jun 12 '21 at 04:34
-
No, 12345 is the "pid" (process id) of the current process listening on the given port. With that knowledge, you're now able to kill that process. @stackunderflow Great answer. Thx – Joseph Merdrignac Jan 20 '22 at 08:23
Borrowed from my answer to this question:
Install the
kill-port
node package as a dev dependency:npm install kill-port --save-dev
Create a
nodemon.json
file in the root of your project containing:{ "events": { "restart": "kill-port 3000", "crash": "kill-port 3000" }, "delay": "1500" }
Then, in your
package.json
file, have something like this:"scripts": { "start-dev": "nodemon app.js", }
Then start your app in dev mode with:
npm run start-dev

- 30,350
- 66
- 462
- 664

- 26,330
- 7
- 49
- 72
-
This didn't work for me. It is weird, because nodemon was working until today. – Tomas Lukac Jun 22 '20 at 10:35
-
-
-
1it works like a charm for me, except for having to install `kill-port` as global instead – jslipknot Jan 15 '21 at 04:06
-
Best Way to counter this problem is directly kill the port with the following command.
fuser -n tcp -k 3000

- 302
- 2
- 8
-
But i will need to run this everytime my server restarts! this is even worse than direct node app.js – Zeyad Shaban Dec 22 '20 at 12:29
You can use the following command at terminal to check which process is using that port:
netstat -aon | findstr '[port_number]'
If that process is not required, you can kill that process and start your own process on port 3000. Otherwise you can always use another port for your application.
Most probably this process will be nodemon, which you can kill and start again.

- 360
- 2
- 10
I had a similar issue with nodemon continuing to watch for file changes even after I closed the terminal. I stopped all node processes (Not just the node process using the port).

- 1,005
- 1
- 11
- 24
It seems that 3000 port is in use. You can kill process that is using 3000 port or you can change port of node from 3000 to any another port.

- 7
- 3