@thomas-devark/onexit
v1.0.2
Published
A utility function that runs a specified callback when the Node.js process exits, regardless of the exit reason.
Downloads
2
Readme
@thomas-devark/onexit
A utility function that runs a specified callback when the Node.js process exits, regardless of the exit reason.
Usage
Importing the Module
import OnExit from "./OnExit";
const OnExit from "./OnExit"
Running a Callback on Process Exit
OnExit(() => {
// do something before process exit
});
API
OnExit(callback: () => void): void
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 pressingCTRL + C
SIGUSR1
andSIGUSR2
: 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.
License
This module is licensed under the MIT License. See the LICENSE
file for more information.