Reputation: 2942
How to correctly close all connections before restarting/shutting down the web server?
Upvotes: 1
Views: 880
Reputation: 3522
I'm using Windows, so in my cmd, I used to use netstat -ano and findstr command to find a node.js process and then taskkill /pid 1234 /F ( 1234 is an example of pid)
However, it was so much work. Now, I use an easier way.
taskkill /F /IM node.exe
This command will close all the node.js processes in one command.
Upvotes: 0
Reputation: 1777
This is a pretty nice npm module which I use to do some cleanups and so on... before the node.js process exists due to any reason (may be due to kill command from outside the process).
https://github.com/sindresorhus/exit-hook
To do the actual cleanup it depends on what you have running. For example if its expressjs do server.close(); and so on....
Upvotes: 1