Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Cross-Platform
  3. signal-exit

signal-exit

BlueOak-1.0.0TypeScript

A Node.js library to reliably execute cleanup handlers when a process exits for any reason.

GitHubGitHub
201 stars27 forks0 contributors

What is signal-exit?

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.

Target Audience

Node.js developers building CLI tools, servers, or long-running processes that require reliable resource cleanup, logging, or finalization steps on exit.

Value Proposition

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.

Overview

when you want to fire an event no matter how a process exits.

Use Cases

Best For

  • Ensuring cleanup code runs when a Node.js CLI tool exits
  • Handling graceful shutdown in long-running Node.js servers
  • Capturing and logging exit codes and signals for debugging
  • Managing resource cleanup (e.g., closing files, DB connections) on process termination
  • Building robust process managers or monitoring tools
  • Preventing resource leaks in Node.js applications with multiple exit paths

Not Ideal For

  • Browser applications requiring actual exit handling (the browser shim is a no-op)
  • Scenarios where preventing all process exits is critical (fatal exceptions or unhandled rejections cannot be stopped)
  • Projects that avoid monkeypatching due to library conflicts or security policies (with the alwaysLast option)
  • Simple, short-lived Node.js scripts with no cleanup needs (where built-in process events suffice)

Pros & Cons

Pros

Comprehensive Exit Coverage

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.

Simple Clean API

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.

Signal Capture Control

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.

Robust Fallback Support

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.

Cons

Limited Exit Prevention

Cannot prevent exits due to numeric codes, fatal exceptions, or unhandled promise rejections, as the README admits these are often already committed to exiting.

Intrusive Monkeypatching

The alwaysLast option monkeypatches process.emit, which can lead to conflicts with other libraries or debugging tools in complex Node.js environments.

Unloads After Handling

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.

Frequently Asked Questions

Quick Stats

Stars201
Forks27
Contributors0
Open Issues7
Last commit7 months ago
CreatedSince 2015

Tags

#nodejs#resource-management#error-handling#signals#cleanup#process-management

Built With

J
JavaScript
N
Node.js

Included in

Cross-Platform1.2k
Auto-fetched 1 day ago

Related Projects

fkillfkill

Fabulously kill processes. Cross-platform.

Stars794
Forks78
Last commit4 months ago
human-signalshuman-signals

Human-friendly process signals

Stars285
Forks14
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub