graceful
Graceful exit when `uncaughtException` emit, base on `process.on('uncaughtException')`.
Last updated 2 years ago by fengmk2 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install graceful 
SYNC missed versions from official npm registry.

graceful

NPM version Test coverage npm download Node.js Version

Graceful exit when uncaughtException emit, base on process.on('uncaughtException').

Why we should use this module

It's the best way to handle uncaughtException on current situations.

Install

npm install graceful

Usage

Please see express_with_cluster example.

This below code just for dev demo, don't use it on production env:

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:

graceful({
  servers: [server1, server2, restapi],
  killTimeout: '15s',
});

ESM and TypeScript

import { graceful } from 'graceful';

Contributors

Contributors

Made with contributors-img.

License

MIT

Current Tags

  • 2.0.0                                ...           latest (2 years ago)

12 Versions

  • 2.0.0                                ...           2 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
  • 0.0.6                                ...           13 years ago
  • 0.0.5                                ...           14 years ago
  • 0.0.4                                ...           14 years ago
  • 0.0.3                                ...           14 years ago
  • 0.0.2                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Maintainers (1)
Downloads
Total 39
Today 0
This Week 2
This Month 27
Last Day 0
Last Week 16
Last Month 12
Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE