Graceful exit when `uncaughtException` emit, base on `process.on('uncaughtException')`.
npm install graceful[![NPM version][npm-image]][npm-url]
[![Test coverage][cov-image]][cov-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/graceful.svg?style=flat-square
[npm-url]: https://npmjs.org/package/graceful
[cov-image]: https://codecov.io/github/node-modules/graceful/coverage.svg?branch=master
[cov-url]: https://codecov.io/github/node-modules/graceful?branch=master
[download-image]: https://img.shields.io/npm/dm/graceful.svg?style=flat-square
[download-url]: https://npmjs.org/package/graceful
Graceful exit when uncaughtException emit, base on process.on('uncaughtException').
It's the best way to handle uncaughtException on current situations.
``bash`
npm install graceful
Please see express_with_cluster example.
This below code just for dev demo, don't use it on production env:
`js
const express = require('express');
const { graceful } = require('graceful');
const app = express()
.use()
.use(function(req, res){
if (Math.random() > 0.5) {
foo.bar();
}
setTimeout(function() {
if (Math.random() > 0.5) {
throw new Error('Asynchronous error from timeout');
} else {
res.end('Hello from Connect!');
}
}, 100);
setTimeout(function() {
if (Math.random() > 0.5) {
throw new Error('Mock second error');
}
}, 200);
})
.use(function(err, req, res, next) {
res.end(err.message);
});
const server = app.listen(1984);
graceful({
servers: [server],
killTimeout: '30s',
});
`
If you have multi servers on one process, you just add them to server:
`js`
graceful({
servers: [server1, server2, restapi],
killTimeout: '15s',
});
`ts``
import { graceful } from 'graceful';

Made with contributors-img.