Gracefully shutdown on both SIGINT + SIGTERM

Most service managers (systemd, docker, etc) use SIGTERM as the shutdown signal by default rather than SIGINT (which is used for interactive CTRL-C).
This commit is contained in:
Kevin Stone
2025-05-29 17:37:40 -07:00
committed by GitHub
parent 97cec114f6
commit cf5c818ee3

View File

@@ -99,8 +99,11 @@ const server = app.listen(port, () => {
});
// graceful shutdown
process.on('SIGINT', () => {
const gracefulShutdown = () => {
server.close(() => {
console.log('Server closed');
});
});
};
process.on('SIGINT', gracefulShutdown);
process.on('SIGTERM', gracefulShutdown);