- The cleanup plugin is an event emitted when the process is exiting
- Execute functions just before the process exits
⚠️ Functions can't be asynchronous
const sh = require('kool-shell')
// Caught exit events and automatically logs errors
sh.caughtExits(true)
function cleanupAction(code) {
if (code === 0) console.log('App is exiting without an error, cool!')
}
// Add a new function to call when exiting
sh.on('cleanup', cleanupAction)
// Remove cleanupAction from the functions to call when exiting
sh.removeListener('cleanup', cleanupAction)
This tells kool-shell to handle SIGINT
and uncaughtException
events.
log
(String, default true): Automatically log errors. If set to false, the errors will not be displayed.
Kool-shell emits cleanup
when your script exits and will immediately call cleanupAction
[More infos about event emitters in Nodejs](https://nodejs.org/api/events.html)