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
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'feat(scope): some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Simone Corsi - @im_simonecorsi