Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🧹 Gracefully shutdown Node.js application: help you handle exit signals and cleanup

License

NotificationsYou must be signed in to change notification settings

simonecorsi/fine

Repository files navigation

"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 bothESM andCommonJS. If, for some reason, you really really need only the CommonJS version refer tov1.4.0.

Table of contents

Installation

You can install locally

npm i @scdev/fine

Usage

// Exampleconsthttp=require("http");const{ promisify}=require("util");constfine=require("@scdev/fine");constserver=http.createServer(/* your handler */);fine([// Tip: you can wait that all connection are closedpromisify(server.close),// or you can just sto accepting new one and continue closing other callbacksserver.close,async()=>{// Throws will be NOOP-edawaitdb.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 usescommitlint 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. SeeLICENSE for more information.

Contact

Simone Corsi -@im_simonecorsi


[8]ページ先頭

©2009-2025 Movatter.jp