Can node.js detect when it is closed?

I want to know if it is possible to detect when the node.js process is closed by clicking the "X" button in Windows. If so, how. I tried process.on("exit");, but it did not work.

+4
source share
1 answer

Catch high

/*
 * Run this code and close the Window before the 10 seconds
 */
var x = setTimeout(function() { console.log('hello world') }, 10000);

process.on('SIGHUP', function() {
  console.log('About to exit');
  process.exit();
});
+4
source

All Articles