Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gracy

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gracy

Execute custom cleanup function before Node.js exits

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

gracy

CI status license npm version

Gracy is a zero-dependency library that provides a simple way to execute custom function before a Node.js process exits. It helps you ensure that your applications perform cleanup tasks, gracefully close resources, and maintain data integrity during (un)expected shutdowns or terminations.

Installation

pnpm i -E gracy

Usage

import { onExit } from 'gracy'

onExit(
    { logger: pinoInstance },
    async () => {
        closeHttpServer()
        await closeDatabaseConnection()
    }
)

Configuration

The onExit function accepts an configuration object as its first argument. The following options are available:

NameDefault valueDescription
loggerLogger to use. You should use libraries for structured logging such as pino, but you can also use the built-in console object. Set to false to disable logging.
events['uncaughtException', 'unhandledRejection']Events to listen to. Triggering these events will cause the process to exit with code 1.
signals['SIGTERM', 'SIGINT']Signals to listen to. Triggering these signals will cause the process to exit with code 0.

License

MIT

Keywords

FAQs

Package last updated on 14 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc