A great feature of the process
module is that it allows you to register listeners to handle signals that the operating system sends to a process. This is helpful when you need to perform certain actions such as cleanup before a process is stopped or terminated. Table 9.1 lists the process events for which you can add listeners.
To register for a process signal, simply use the on(
event, callback)
method. For example, to register an event handler for the SIGBREAK
event, you would use the following code:
process.on('SIGBREAK', function(){
console.log("Got a SIGBREAK");
});