Package detail

graceful

node-modules99.2kMIT2.0.0

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

graceful, uncaught, uncaughtException, error

readme

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

changelog

Changelog

2.0.0 (2024-12-15)

⚠ BREAKING CHANGES

  • drop Node.js < 18.19.0 support

part of https://github.com/eggjs/egg/issues/3644

https://github.com/eggjs/egg/issues/5257

closes https://github.com/node-modules/graceful/issues/16

Summary by CodeRabbit

  • New Features

    • Introduced a new ESLint configuration for TypeScript and Node.js.
    • Added a new GitHub Actions workflow for package publishing.
    • Implemented a new TypeScript configuration for enhanced type safety.
    • Created a new test suite for validating worker process behavior.
    • Added a new test suite for verifying child process behavior.
  • Bug Fixes

  • Updated Node.js CI workflow to include newer versions and improved configurations.

  • Documentation

    • Enhanced README with updated badges and installation instructions.
    • Updated example documentation to reflect file extension changes.
  • Chores

    • Removed outdated files and workflows to streamline the repository.
    • Updated .gitignore to exclude additional files and directories.

Features

  • support cjs and esm both by tshy (#17) (7192a67)

1.1.0 / 2022-09-22

features

others

1.0.2 / 2018-10-31

others

1.0.1 / 2016-06-23

  • fix: print more server connections log (#9)
  • fix: ignore GRACEFUL_COV env

1.0.0 / 2014-11-05

  • refator: use express instead connect on example

0.1.0 / 2014-05-29

  • send disconnect message

0.0.6 / 2014-02-17

  • add console.error(err.stack) by default (@dead-horse)
  • add npm image
  • support coveralls

0.0.5 / 2013-04-18

  • fixed header sent bug

0.0.4 / 2013-04-18

  • add options.worker
  • add custom error log demo

0.0.3 / 2013-04-14

  • Let http server set Connection: close header, and close the current request socket. fixed #2

0.0.2 / 2013-04-14

  • Support multi servers close fixed #1
  • update readme

0.0.1 / 2013-04-12

  • first commit