remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.21k stars 1.72k forks source link

nodemon doesn't kill the last listening port when resaving the project #2128

Closed Bardala closed 9 months ago

Bardala commented 1 year ago

nest@1.0.0 start npm-run-all --parallel start:backend start:frontend

nest@1.0.0 start:backend cd backend && npm start

nest@1.0.0 start:frontend cd frontend && npm start

backend@1.0.0 start nodemon src/server.ts

frontend@0.1.0 start craco start

Expected behaviour

[nodemon] restarting due to changes...
[nodemon] starting ts-node src/server.ts
Server listening on port 4001

Actual behaviour

stackoverflow

mvaibhav77 commented 1 year ago

Hi @Bardala,

Here are some methods you can try to solve your problem:-

If the issue persists, feel free to reach out for further assistance. I'm here to help.

bradleyayers commented 11 months ago

This happens to me too if I try to run two commands in sequence i.e. if I prefix exec with true && then I run into the problem where the server isn't shut down properly and I get EADDRINUSE. As soon as I remove the true && it's reliably frees the port when restarting.

github-actions[bot] commented 11 months ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

basicdays commented 10 months ago

The only reliable way I've found to handle graceful restarts with nodemon was to catch SIGUSR2 process signal and perform a httpServer.close() in the callback. This should hopefully allow your application code to free up its resources before nodemon aggressively restarts it again. See docs here.

If your graceful exit code requires anything async though, you'll get random race conditions since nodemon isn't properly waiting for the process to exit before starting it again. See issue #1889

github-actions[bot] commented 10 months ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

github-actions[bot] commented 9 months ago

Automatically closing this issue due to lack of activity