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 🙏

© 2024 – Pkg Stats / Ryan Hefner

shinu

v0.2.1

Published

Shinu in japanese means Die, and this library pevents your process from dying

Downloads

10

Readme

Shinu - Elegant Process Exception Handling

Rate this package

Shinu is a lightweight Node.js library that makes it easy to handle signals and other process events in your application. It provides a simple interface for registering signal handlers and logging process information.

Features

  • Simple API for adding and removing signal handlers
  • Default signal handlers for common signals (SIGINT, SIGTERM, SIGQUIT)
  • Option to log process information for debugging purposes
  • Option to handle uncaught exceptions and unhandled rejections

Installation

You can install Shinu using npm or yarn:

npm install shinu

or

yarn add shinu

Usage

Here's an example of how to use Shinu to handle the SIGINT signal:

const { Shinu } = require('shinu');

const shinu = new Shinu();

shinu.addHandler('SIGINT', (signal) => {
  console.log(`Received ${signal}`);
  process.exit(0);
});

shinu.start();

In this example, we create a new Shinu instance and add a handler for the SIGINT signal. The handler simply logs a message and exits the process. We then call the start method to begin listening for signals.

By default, Shinu includes handlers for the SIGINT, SIGTERM, and SIGQUIT signals, so you don't need to add these manually.

You can also pass options to the Shinu constructor to customize its behavior:

const { Shinu } = require('shinu');

const shinu = new Shinu({
  debug: true,
  handlers: [
    {
      signal: 'SIGUSR1',
      handler: (signal) => {
        console.log(`Received ${signal}`);
      },
    },
  ],
});

shinu.start();

In this example, we pass an options object to the Shinu constructor to enable debug logging and add a custom signal handler for SIGUSR1.

API

new Shinu(options: IShinuOptions)

Creates a new Shinu instance with the specified options.

const shinu = new Shinu({
  debug: true,
  handlers: [
    {
      signal: 'SIGUSR1',
      handler: (signal) => {
        console.log(`Received ${signal}`);
      },
    },
  ],
});

options.debug

Type: boolean Default: false

Enables debug mode. When debug mode is enabled, Shinu will log detailed process information for each signal received.

options.handlers

Type: IHandler[] Default: []

An array of signal handlers to register when the Shinu instance is started.

options.logger

Type: (message: string) => void Default: console.log

A function that will be called to log messages. You can use your own logger or replace the default console.log method.

options.handleUncaughtException

Type: boolean Default: false

Enables handling of uncaught exceptions. When this option is enabled, Shinu will log any uncaught exceptions and exit the process.

options.handleUnhandledRejection

Type: boolean Default: false

Enables handling of unhandled rejections. When this option is enabled, Shinu will log any unhandled rejections and exit the process.

shinu.addHandler(signal: signals, handler: handler)

Adds a handler function for the specified signal.

shinu.addHandler('SIGUSR1', (signal) => {
  console.log(`Received ${signal}`);
});

shinu.removeHandler(signal: signals, handler?: handler)

Removes the specified handler function for the specified signal. If no handler function is provided, removes all handlers for the signal.

shinu.removeHandler('SIGUSR1');

shinu.removeAllHandlers()

Removes all registered signal handlers.

shinu.removeAllHandlers();

shinu.start()

Starts listening for registered signals and runs any associated handlers.

shinu.start();

shinu.isHandlerAdded(signal: signals, handler: handler)

Returns true if the specified handler function is registered for the specified signal, false otherwise.

const isHandlerAdded = shinu.isHandlerAdded('SIGUSR1', myHandlerFunction);

License

This project is licensed under the MIT License. See the LICENSE file for details.