I have a simple shell script written in Node.js and I'm trying to do some cleanup before the process exits (⌃C). I've written the following code but for some reason the cleanup function doesn't complete. Any ideas why?
if (keepAlive) {
process.stdin.resume();
['exit', 'SIGINT'].forEach(function(signal) {
process.on(signal, function() {
console.log("Received Signal: '" + signal + "'. Cleaning up...");
cleanup(function(err) {
console.log('this function is called but does not finish')
process.exit();
});
});
});
else {
process.exit();
}
I'm using Node v6.9.2