npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@eliware/signals

v1.1.1

Published

Graceful shutdown signal handler utility for Node.js (ESM and CommonJS)

Readme

eliware.org

@eliware/signals npm versionlicensebuild status

Graceful shutdown signal handler utility for Node.js (ESM and CommonJS)


Table of Contents

Features

  • Register handlers for process signals (e.g., SIGTERM, SIGINT, SIGHUP)
  • Register async shutdown hooks to run on signal or process exit
  • Customizable logger and process object
  • Simple API for both ESM and CommonJS
  • TypeScript type definitions included
  • Well-tested with Jest

Installation

npm install @eliware/signals

Usage

ESM Example

import log from '@eliware/log';
import registerSignals from '@eliware/signals'; // Default export
// or: import { registerSignals } from '@eliware/signals';
const { shutdown, getShuttingDown } = registerSignals({ log });

CommonJS Example

const log = require('@eliware/log');
const registerSignals = require('@eliware/signals'); // Default export
// or: const { registerSignals } = require('@eliware/signals');
const { shutdown, getShuttingDown } = registerSignals({ log });

Shutdown Hooks Example

You can call registerSignals multiple times to add async shutdown hooks. All hooks will be run (in order of registration) when a signal is received or the process exits (via exit or beforeExit).

// Simulate a resource that needs cleanup (e.g., database connection)
const fakeDb = {
  close: async () => {
    return new Promise(resolve => setTimeout(() => {
      log.info('Fake DB connection closed');
      resolve();
    }, 100));
  }
};

// Register signal handlers
registerSignals({ log });

// Add shutdown hook for closing the fake DB connection
registerSignals({
  log,
  shutdownHook: async (signal) => {
    await fakeDb.close();
    log.info(`Cleanup complete on ${signal}`);
  }
});

Note: Both the default export and named export registerSignals are available in both ESM and CommonJS.

API

registerSignals(options?)

Registers shutdown handlers for the specified signals and allows registering async shutdown hooks.

Options

  • processObj (default: process): The process object to attach handlers to.
  • log (default: @eliware/log): Logger for output. Should have debug, info, warn, and error methods.
  • signals (default: [ 'SIGTERM', 'SIGINT', 'SIGHUP' ]): Array of signals to listen for.
  • shutdownHook (optional): An async function to run during shutdown. You can call registerSignals multiple times to add multiple hooks.

Returns

An object with:

  • shutdown(signal: string): Promise<void> — Manually trigger shutdown logic.
  • getShuttingDown(): boolean — Returns whether shutdown is in progress.

Shutdown hooks will run on signal, process.exit, or beforeExit.

TypeScript

Type definitions are included:

import registerSignals, { RegisterSignalsOptions } from '@eliware/signals';

// Optionally provide options
const options: RegisterSignalsOptions = {
  processObj: process, // optional, defaults to process
  log: myLogger,       // optional, defaults to @eliware/log
  signals: ['SIGTERM', 'SIGINT', 'SIGHUP'], // optional, defaults as shown
  shutdownHook: async (signal) => { /* ... */ } // optional
};

const { shutdown, getShuttingDown } = registerSignals(options);

// Types:
// interface RegisterSignalsOptions {
//   processObj?: NodeJS.Process;
//   log?: typeof log;
//   signals?: string[];
//   shutdownHook?: (signal: string) => Promise<void>;
// }
//
// function registerSignals(options?: RegisterSignalsOptions): {
//   shutdown: (signal: string) => Promise<void>;
//   getShuttingDown: () => boolean;
// };

Support

For help, questions, or to chat with the author and community, visit:

Discordeliware.org

eliware.org on Discord

License

MIT © 2025 Eli Sterling, eliware.org

Links