A utility function that runs a specified callback when the Node.js process exits, regardless of the exit reason.
npm install @thomas-devark/onexitA utility function that runs a specified callback when the Node.js process exits, regardless of the exit reason.
``typescript`
import OnExit from "./OnExit";
const OnExit from "./OnExit"
`typescript`
OnExit(() => {
// do something before process exit
});
Adds event listeners for process events that may cause the process to exit, and runs the specified callback when any of these events are triggered. The events include:
- exit: emitted when the Node.js process is about to exitSIGINT
- : emitted when the user interrupts the process by pressing CTRL + CSIGUSR1
- and SIGUSR2: emitted when the process receives a user-defined signaluncaughtException
- : emitted when an unhandled exception occurs in the processSIGTERM
- : emitted when the process is terminated by an external signal
The callback parameter is a function that will be called when any of these events are triggered. It should not accept any parameters or return any values.
This module is licensed under the MIT License. See the LICENSE` file for more information.