How Do I Shut Down My Express Server Gracefully When Its Process Is Killed?

后端 未结 6 671
清酒与你
清酒与你 2020-12-08 00:50

When running my Express application in production, I want to shut down the server gracefully when its process is killed (i.e. a SIGTERM or SIGINT is sent).

Here is a

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 01:15

    Try the NPM express-graceful-shutdown module, Graceful shutdown will allow any connections including to your DB to finish, not allow any fresh/new ones to be established. Since you are working with express that may be the module you are looking for, however a quick NPM search will reveal a whole list of modules suited to Http servers etc.

提交回复
热议问题