1.0.2 • Published 1 year ago

@thomas-devark/onexit v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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 exit
  • SIGINT: emitted when the user interrupts the process by pressing CTRL + C
  • SIGUSR1 and SIGUSR2: emitted when the process receives a user-defined signal
  • uncaughtException: emitted when an unhandled exception occurs in the process
  • SIGTERM: 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.

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago