Node.js process exit


To perform an action right before a Node.js script exits, you can listen to process exit:

// script.js

process.on('exit', function() {
    console.log('exit');
});

Now when you run the script, exit is logged out:

node script
exit


Please support this site and join our Discord!