This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 400,000 packages pre-installed, including finis
with all npm
packages installed. Try it out:
require()
any package directly from npmawait
any promise instead of using callbacks (example)This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
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:
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.
process.exit
by defaultSIGTERM
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)