Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
signal-exit | 3.0.7 | 3.76 kB | ISC | prod |
Signal-exit is a JavaScript package that aids in firing an event, regardless of how a process exits. This can include a process reaching the end of execution, explicitly having process.exit(code)
called, process.kill(pid, sig)
called, or receiving a fatal signal from outside the process. Signal-exit proves to be an advantageous tool when developers wish to capture all possible process exit scenarios within their applications.
To use the signal-exit package, you first need to import it into your JavaScript application. There are two ways to do this, either by using the ES6 import
syntax or the CommonJS require
syntax. After the importation is successfully done, you can then call the onExit
function which fires when a process exits.
Here is a simple usage example demonstrating these steps:
// Import signal-exit using ES6 syntax
import { onExit } from 'signal-exit';
// Or you can import using CommonJS syntax
// const { onExit } = require('signal-exit');
onExit((code, signal) => {
console.log('process exited!', code, signal)
});
The onExit
function takes a callback function as its parameter which will be executed when the process exits. The callback function receives the exit code and signal as its arguments.
The official documentation for signal-exit can be found in the package's README on GitHub at https://github.com/tapjs/signal-exit
. Here, you will find a thorough description of the package, how to use it, example code snippets, and other useful explanations and references. For a deep-dive into the package usage and customization options, this is the best place to start.