exit-hook
Run some code when the process exits
Last updated 4 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install exit-hook 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.2.0                                ...           latest (4 months ago)

6 Versions

  • 2.2.0                                ...           4 months ago
  • 2.1.0                                ...           5 months ago
  • 2.0.0                                ...           a year ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 54
This Week 54
This Month 78,738
Last Day 1,119
Last Week 21,976
Last Month 107,605
Dependencies (0)
None
Dev Dependencies (4)
Dependents (134)

Copyright 2014 - 2016 © taobao.org |