Description
A library to safely shutdown your NodeJS app
Usage
var shutdown = ; shutdown; shutdown; // NOTE: This is not an event emitter kind. calling this multiple times will cause the previous value to be overwritten. In short, there can only be one, and it supports promise { http; // stop accepting HTTP requests // or you're using express app; // stop accepting more incoming requests var timer_id = ;}
In other modules
var shutdown = ; // it's a singleton! if shutdownshutting_down // do something great!
Shutdown through socket -- in your terminal
// shutdown in 120 seconds $ echo shutdown | nc -U MyApp.sock // shutdown in 10 seconds$ echo shutdown 10 | nc -U MyApp.sock // the shutdown command can be called repeatedly and it will reset the timer to the new one mentioned
Use case
Safely shutdown your app by stop accepting incoming requests.
Precaution
It is recommended to not close database connections so that pending tasks should be able to complete accordingly
Bonus feature
shutdown; // set your app to maintenance mode! shutdown; // set your app to maintenance mode!
in your terminal
$ echo maintenance | nc -U MyApp.sock $ echo yet_another_function | nc -U MyApp.sock