Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonecorsi/fine
๐งน Gracefully shutdown Node.js application: help you handle exit signals and cleanup
https://github.com/simonecorsi/fine
event exit fine graceful handler hook javascript nodejs npm process quit shutdown sigint signal sigterm stop terminate
Last synced: 2 months ago
JSON representation
๐งน Gracefully shutdown Node.js application: help you handle exit signals and cleanup
- Host: GitHub
- URL: https://github.com/simonecorsi/fine
- Owner: simonecorsi
- License: mit
- Created: 2020-06-17T06:58:56.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-11T10:45:54.000Z (10 months ago)
- Last Synced: 2024-04-11T11:46:25.416Z (10 months ago)
- Topics: event, exit, fine, graceful, handler, hook, javascript, nodejs, npm, process, quit, shutdown, sigint, signal, sigterm, stop, terminate
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@scdev/fine
- Size: 2.27 MB
- Stars: 32
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fine
> "Fine" [fรฌ-ne] - means "End" in Italian.
> The point in time when an action, event, or phenomenon ceases or is completed; the conclusion.## 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.
## ESM
This package now exports both `ESM` and `CommonJS`. If, for some reason, you really really need only the CommonJS version refer to `v1.4.0`.
## Table of contents
- [Installation](#installation)
- [Usage](#usage)
- [Arguments](#arguments)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)## Installation
You can install locally
```sh
npm i @scdev/fine
```## Usage
```js
// 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
```js
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 [commitlint](https://commitlint.js.org/) 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](./LICENSE) for more information.
## Contact
Simone Corsi - [@im_simonecorsi](https://twitter.com/im_simonecorsi)