I was just trying to work with signals like SIGTERM and SIGINT. The idea is I want to send SIGTERM signal with process.kill(process.pid, "SIGTERM") when something happens and then handle that signal with process.on("SIGTERM", callback).
My expectation is that when process.kill(process.pid, "SIGTERM") runs, the SIGTERM handler should run the callback function and do some cleanup work.
But this does not happen and process exits without running the callback function.
if (condition) {
process.kill(process.pid, 'SIGTERM');
}
process.on('SIGTERM', () => {
console.log('SIGTERM SIGNAL RECEIVED');
});