exit-hook
Run some code when the process exits
The process.on('exit')
event doesn't catch all the ways a process can exit.
This package is useful for cleaning up before exiting.
Install
$ npm install exit-hook
Usage
import exitHook from 'exit-hook';
exitHook(() => {
console.log('Exiting');
});
exitHook(() => {
console.log('Exiting 2');
});
throw new Error('🦄');
Removing an exit hook:
import exitHook from 'exit-hook';
const unsubscribe = exitHook(() => {});
unsubscribe();
API
exitHook(onExit)
Returns a function that removes the hook when called.
onExit
Type: Function
The callback function to execute when the process exits.