2.0.0 • Published 2 years ago

@scdev/fine v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

fine

"Fine" means "End" in Italian, fì-ne Cessazione definitiva, punto estremo, nello spazio e nel tempo di qualcosa.

About

Zero dependency and opinionated package that gracefully shutdown Node.js applications.

It provides extendability by taking an array of callbacks that will be executed serially to allow closing user-defined resources, eg: a database connection, drain streams, etc; before timeout exits the main process.

Table of contents

Installation

You can install locally

npm i @scdev/fine

Usage

// Example
const http = require("http");
const { promisify } = require("util");
const fine = require("@scdev/fine");

const server = http.createServer(/* your handler */);

fine(
  [
    // Tip: you can wait that all connection are closed
    promisify(server.close),
    // or you can just sto accepting new one and continue closing other callbacks
    server.close,

    async () => {
      // Throws will be NOOP-ed
      await db.disconnect();
    },
  ],
  {
    timeout: 2000,
    events: ["SIGINT", "SIGTERM", "uncaughtException", "unhandledRejection"],
  }
);

// ...

Arguments

fine(callbacks, options);
parametertypedescriptiondefault
callbacksfunction[]Collection of callback for custom closing events, eg: db.disconnect()[]
options.timeoutNumberThe time before exiting the process2000
options.eventsstring[]The events the process will listen on["SIGINT", "SIGTERM", "uncaughtException", "unhandledRejection"]
options.unrefbooleanShould the timeout keep the process alive or notfalse

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 commitlint with Angular configuration 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

2.0.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.14

3 years ago

1.0.11

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago