nodemon: Error: listen EADDRINUSE
nodemon -v: 1.17.3node -v: 8.10.0- Operating system/terminal environment: MacOS 10.13.4
- Command you ran:
nodemon app.js
Expected behaviour
Should restart the app when there are changes using the same http server (host & server)
Actual behaviour
Restarts the app but throwing an error saying the EADDRINUSE.
Steps to reproduce
- Create a small ExpressJS app. At least 2 files:
app.jsanddummy.js - Let
app.jsrequiredummy.js - Listen to a host (i.e. 127.0.0.1) and port (i.e. 4000)
- run
nodemon app.js - Edit and save
dummy.js
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 44 (10 by maintainers)
Solution for Googlers…
For me the problem happens due to use of
concurrently(which itself is a workaround the problem that nodemon doesn’t understand I need more then one process running). If I’m not mistaken concurrently closes and nodemon considers job done.Even with out use of concurrently I’ve had plenty of similar issues in the past due to conflicts of nodemon exiting and the process exiting.
You can solve practically all nonsensical port related problems like this:
Essentially the above says “kill anything running on TCP ports 5000 and 3050”
You may also wish to add this in a script before nodemon starts:
Also you NEED to add this too to the nodemon command:
If there is no delay then 2 times out of 10 you’ll get some port conflict.
The delay also prevents nodemon from spamming restarts since it resets every new change (preventing yet another thing that causes conflicts).
It would be nicer if killing ports before restart was just something that was built in (along with the ability to execute multiple scripts at once).
cc @remy
I was having the same problem and in the latest version - 1.18.7 this seems to be fixed. Cheers!!
A Node.js style solution (work in Mac, Linux, Windows):
yarn add kill-portin
nodemon.json:Replace your port:
1.18.7 has same problem on here.
@LBWright thanks! Was having the same issue but
killall nodefixed it.Yes! 1.18.7 is working!
My solution:
nodemon.jsonnodemon.shsrc/server.jsThe trick is to kill the port whenever nodemon start, not when it restarts/crash.
@remy Nodemon process sustains after parent process being killed (Webpack out of memory or something similar) in my case. Here are codes to replicate this case.
@remy Can replicate via
nestjssample project:nest docs: https://docs.nestjs.com/first-steps
Update any .ts file in sample project, you will see
Error: listen EADDRINUSEMy env: MacOS,Node v10.9.0, “nodemon”: “^1.18.6”,
I had the same issue that I fixed by adding
--signal SIGTERMI haven’t been able to replicate it since I had the error. When I did encounter the error again (only one more time), I used the
killall nodecommand and I haven’t had the error since. It might be an that the OS isn’t killing the process before the server restarts. But I can only speculate. I’m sorry that I haven’t been much help, I’m still relatively new to the dev world and I’m trying to provide as much help as I can.Edit: if I encounter the error, I will immediately retest with
nodemon --signal SIGTERM.This has been mentioned again recently on a closed issue. https://github.com/remy/nodemon/issues/1025#issuecomment-381025138.
I’ll try to create another test and hopefully I could pinpoint the cause.