npm

Does your artifact manager get in the way? Join us on Oct. 8 at 10am PT, to discuss how npm can help.Sign up »

exit-hook

2.2.0 • Public • Published

exit-hook Build Status

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.

Check out async-exit-hook if you need async support.

Install

$ npm install exit-hook

Usage

const exitHook = require('exit-hook');
 
exitHook(() => {
    console.log('Exiting');
});
 
// You can add multiple hooks, even across files
exitHook(() => {
    console.log('Exiting 2');
});
 
throw new Error('🦄');
 
//=> 'Exiting'
//=> 'Exiting 2'

Removing an exit hook:

const exitHook = require('exit-hook');
 
const unsubscribe = exitHook(() => {});
 
unsubscribe();

API

exitHook(callback)

Returns a function that removes the hook when called.

callback

Type: Function

The callback to execute when the process exits.

License

MIT © Sindre Sorhus

install

npm i exit-hook

Downloadsweekly downloads

2,311,531

version

2.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability