nexit
Zero Dependency utility to exit NodeJs gracefully
Install
npm install nexit
API
Constructor parameters
Parameter | Default | Description |
---|---|---|
options.shutdownDelay | 30000 | shutdown delay(ms) |
options.exitDelay | 300 | exit delay(ms) |
Quick Start
const Nexit = ; ;
or
; ;
Description
This library aims to delay process exit by a configurable amount of time to let service/traffic orchestrator to stop routing active traffic so that the process can be killed safely.
SIGINT
,SIGTERM
anduncaughtException
signals- start a timer with
shutdownDelay
after catching one of the signals above. - fire an event with
NEXIT_SHUTDOWN
to let application know about the state
application can use this event for its
healthz
route as below.
- once
shutdownDelay
timer is expired, start a new timer withexitDelay
- fire an event with
NEXIT_EXIT
to let application know about the state - at this point, application may exit on its own at any time if node event loop is fully cleared
- once
exitDelay
timer is expired, application will be killed forcefully byprocess.exit
command
Usage
Simple healthz
route implementation for ExpressJs.
const express = ;const Nexit = ; const app = ; const nexit = ;nexit;nexit; app; app;
See ./demo
for a working example;
cd ./demonpm installnode index.js