Register tasks to perform when the process exits.
npm install on-exitEasily register tasks to perform when the current node process exits.
``bash`
npm install on-exit
`js
var onExit = require('on-exit');
onExit(function() {
console.log('Closing db connections...');
db.close();
});
onExit(function() {
console.log('Performing other cleanup...');
app.cleanup();
});
`
When the process exits handlers will be run in the order that they were added.
`js
var onExit = require('on-exit').logger(function(msg) {
myCustomLogger.log(msg);
});
// Or to console.log
onExit.logger(console.log.bind(console));
``