alex.mironov
alex.mironov

Reputation: 2942

How to restart node.js server gracefully?

How to correctly close all connections before restarting/shutting down the web server?

Upvotes: 1

Views: 880

Answers (2)

Jin Lee
Jin Lee

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

sagie
sagie

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

Related Questions