A Node.js library to reliably execute cleanup handlers when a process exits for any reason.
signal-exit is a Node.js library that allows developers to register cleanup handlers that execute whenever a process exits, regardless of whether it's due to normal termination, an explicit exit call, or a fatal signal. It solves the problem of unreliable cleanup in Node.js applications by ensuring handlers run consistently across all exit paths.
Node.js developers building CLI tools, servers, or long-running processes that require reliable resource cleanup, logging, or finalization steps on exit.
Developers choose signal-exit for its simplicity and reliability—it handles all exit scenarios with a minimal API, avoids common pitfalls in signal handling, and provides options like signal capture and ordered execution.
when you want to fire an event no matter how a process exits.
Handles all exit causes including normal termination, explicit process.exit() calls, and fatal signals, ensuring cleanup runs reliably across scenarios as described in the README.
The onExit function with a removal return makes it easy to register and manage handlers without complex configuration, aligning with the library's philosophy of simplicity.
Allows handlers to return true to capture and prevent signal exits, giving developers fine-grained control over exit behavior, as detailed in the Capturing Signal Exits section.
Includes a no-op implementation for unsuitable environments and a browser shim, providing cross-environment compatibility without breaking code, per the README's graceful fallbacks.
Cannot prevent exits due to numeric codes, fatal exceptions, or unhandled promise rejections, as the README admits these are often already committed to exiting.
The alwaysLast option monkeypatches process.emit, which can lead to conflicts with other libraries or debugging tools in complex Node.js environments.
Once onExit handlers fire, the machinery unloads, so subsequent exits or signals in the same event loop might not be captured, limiting use in recursive exit scenarios.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.