Run your callback before node exit, pass exit code
and signal name
as arguments
npm install finis --save
finis() installs a callback function which will be run just before the node process exits.
The callback function will be called when:
- the process exits normally
- the user presses Ctrl+C
- an exception is uncaught
const finis = require('finis')
finis((code, signal, error) => {
console.log(`finis(${code}, ${signal}, ${error})`)
})
import finis from 'finis'
finis((code: number, signal: 'exit'|'SIGINT'|'SIGTERM'|'uncaughtException', error?: Error) => {
console.log(`finis(${code}, ${signal}, ${error})`)
})
You may call finis() multiple times to install multiple callback functions.
- Do not call
process.exit
by default - Add support to
SIGTERM
- Add support to TypeScript
This module is inspired by @jtlapp/node-cleanup, which is borrowed and modified from CanyonCasa's answer to a stackoverflow question. I found the code necessary for all my node projects. See the stackoverflow answer for more examples of use.
Huan LI <zixia@zixia.net> (http://linkedin.com/in/zixia)
- Code & Docs © 2016-2017 Huan LI <zixia@zixia.net>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons