A tiny middleware for a sweet graceful shutdown procedure. Just listen to amazing Grace while closing the app. Existing connections will be respected during a configurable timeout while new ones are being refused.
This middleware is recommended if you want to harden your nodejs app for zero down time during production.
var amazingGrace =express =app =server = http// Pass on server instance, required parameterapp
What happens on app.kill('...')?
A graceful shutdown procedure is being initiated, asking the server to close and forcing to close all existing connections after a given
timeout so that they have a chance to i.E. save data before oblivion.
During that timeout, new connections to the server won't be possible. After that timeout
process.kill(...) is called and the server is shut down.
If you wish more debug information, you can pass on the log function directly i.E.
console.log or even
bunyan.info.bind(bunyan), whatever log level you wish. Use of bind() is recommended.
Depending on your app performance you might want to increase that to make sure no data loss occurs between restarts.
MIT. Copyright (C) Michael Heuberger