https://github.com/binarykitchen/amazing-grace
A tiny ExpressJS middleware for a sweet, graceful shutdown procedure
https://github.com/binarykitchen/amazing-grace
Last synced: about 1 year ago
JSON representation
A tiny ExpressJS middleware for a sweet, graceful shutdown procedure
- Host: GitHub
- URL: https://github.com/binarykitchen/amazing-grace
- Owner: binarykitchen
- License: other
- Created: 2015-01-03T06:28:29.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T10:26:40.000Z (about 2 years ago)
- Last Synced: 2025-03-16T01:03:18.223Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
amazing-grace
=============
[](https://travis-ci.org/binarykitchen/amazing-grace)
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.
## Example
```js
var amazingGrace = require('amazing-grace'),
express = require('express'),
app = express(),
server = http.createServer(app)
// Pass on server instance, required parameter
app.use(amazingGrace(server))
```
## 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.
## Options (example)
```js
app.use(amazingGrace(server, {log: console.log, timeout: 50}))
```
### log
Default: none
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.
### timeout
Default: 100ms
Depending on your app performance you might want to increase that to make sure no data loss occurs between restarts.
## License
MIT. Copyright (C) [Michael Heuberger](https://binarykitchen.com)