Is it possible for a node script to detect if it was terminate from "external" (p.e.: kill) or internal by a script error?
To be more precise: The first case should't not be a main process that "observe" its children, or a additional script that "looks" if the main script is still running.
2nd case: without putting everything in try-except-blocks. I m looking for a function that is called when an error would stop the script.
var exceptionOccured = false;
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
exceptionOccured = true;
process.exit();
});
process.on('exit', function(code) {
if(exceptionOccured) console.log('Exception occured');
else console.log('Kill signal received');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With