Giter VIP home page Giter VIP logo

gracy's Introduction

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(
    async () => {
        closeHttpServer()
        await closeDatabaseConnection()
    },
    { logger: pinoInstance }
)

Configuration

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

Name Default value Description
logger console Logger to use. You should use libraries for structured logging such as pino. Set to false to disable logging.
logLevel 'info' Log level to use. Valid options are 'debug', 'info', 'error'.
logPrefix '[gracy] ' Prefix to use for log messages. Set to empty string to disable prefixing.
timeout 10_000 Timeout (in milliseconds) to wait for the function to finish. If the function does not finish in time, the process will exit with code 1.
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

gracy's People

Contributors

github-actions[bot] avatar renovate[bot] avatar samialdury avatar samialdury-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

gracy's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • pnpm/action-setup v2
  • actions/setup-node v4
.github/workflows/release.yml
  • actions/checkout v4
  • crazy-max/ghaction-import-gpg v6
  • pnpm/action-setup v2
  • actions/setup-node v4
  • actions/cache v4
npm
package.json
  • @arethetypeswrong/cli 0.13.5
  • @commitlint/cli 18.4.4
  • @samialdury/config 6.2.0
  • @types/node 20.11.5
  • eslint 8.56.0
  • glob 10.3.10
  • husky 8.0.3
  • lint-staged 15.2.0
  • prettier 3.1.1
  • publint 0.2.7
  • semantic-release 22.0.12
  • tsup 8.0.1
  • tsx 4.7.0
  • typescript 5.3.3
  • node >=20
  • pnpm >=8

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.