UNPKG

1.18 kBMarkdownView Raw
1# signal-exit
2
3[![Build Status](https://travis-ci.org/bcoe/signal-exit.png)](https://travis-ci.org/bcoe/signal-exit)
4[![Coverage Status](https://coveralls.io/repos/bcoe/signal-exit/badge.svg?branch=)](https://coveralls.io/r/bcoe/signal-exit?branch=)
5[![NPM version](https://img.shields.io/npm/v/signal-exit.svg)](https://www.npmjs.com/package/signal-exit)
6
7When you want to fire an event no matter how a process exits:
8
9* reaching the end of execution.
10* explicitly having `process.exit(code)` called.
11* having `process.kill(pid, sig)` called.
12* receiving a fatal signal from outside the process
13
14Use `signal-exit`.
15
16```js
17var onExit = require('signal-exit')
18
19onExit(function (code, signal) {
20 console.log('process exited!')
21})
22```
23
24## API
25
26`var remove = onExit(function (code, signal) {}, options)`
27
28The return value of the function is a function that will remove the
29handler.
30
31Note that the function *only* fires for signals if the signal would
32cause the proces to exit. That is, there are no other listeners, and
33it is a fatal signal.
34
35## Options
36
37* `alwaysLast`: Run this handler after any other signal or exit
38 handlers. This causes `process.emit` to be monkeypatched.