@scdev/fine

Graceful shutdown Node.js application, this module helps handling process exit signals and closing pending jobs

Usage no npm install needed!

<script type="module">
  import scdevFine from 'https://cdn.skypack.dev/@scdev/fine';
</script>

README

fine

About

The purpose of this package is helping in gracefully shutdown Node.js applications the "good way" (opinated clearly), while also providing some minor extendability!

This package also takes an array of callbacks that will get executed serially to allow closing user defined resource, eg: a database connection.

Table of contents

Installation

You can install locally

npm i @scdev/fine

Usage

const fine = require("@scdev/fine");
fine(
  [
    redis.disconnect,
    async () => {
      await db.disconnect();
      // some more logic
      return "ok";
    },
  ],
  {
    timeout: 2000,
    events: ["SIGINT", "SIGTERM", "uncaughtException", "unhandledRejection"],
  }
);

Arguments

fine(callbacks, options);
parameter type description default
callbacks function[] Collection of callback for custom closing events, eg: db.disconnect() []
options.timeout Number The time before exiting the process 2000
options.events string[] The events the process will listen on ["SIGINT", "SIGTERM", "uncaughtException", "unhandledRejection"]
options.unref boolean Should the timeout keep the process alive or not false

Contributing

Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.

This projects uses commitizen so be sure to use standard commit format or PR won't be accepted

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat(scope): some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Simone Corsi - @im_simonecorsi