In Node.js it's possible to respond to SIGTERM signal events.
From the official documentation:
function handle(signal) {
console.log(`Received ${signal}`);
}
process.on('SIGTERM', handle);
Is it necessary or advisable to terminate the process with process.exit() in the event handler?
For example:
async function closeGracefully() {
await closeDbConnection();
await stopApplication();
process.exit();
}
process.on('SIGTERM', closeGracefully);