exit-hook
Run some code when the process exits
Last updated 7 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 (7 months ago)

6 Versions

  • 2.2.0                                ...           7 months ago
  • 2.1.0                                ...           7 months ago
  • 2.0.0                                ...           2 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 84
This Week 11,780
This Month 59,557
Last Day 3,811
Last Week 20,320
Last Month 80,458
Dependencies (0)
None
Dev Dependencies (4)
Dependents (137)

Copyright 2014 - 2017 © taobao.org |