UNPKG

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