log-process-errors
Show some ❤️ to process errors
Last updated 2 years ago by ehmicky .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install log-process-errors 
SYNC missed versions from official npm registry.
<picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ehmicky/design/main/log-process-errors/log-process-errors_dark.svg"/> log-process-errors logo </picture>

Node TypeScript Codecov Mastodon Medium

📰 Medium article.

Show some ❤️ to Node.js process errors.

This improves process errors: uncaught exceptions, unhandled promises, promises handled too late and warnings.

Hire me

Please reach out if you're looking for a Node.js API or CLI engineer (11 years of experience). Most recently I have been Netlify Build's and Netlify Plugins' technical lead for 2.5 years. I am available for full-time remote positions.

Features

Install

Production code (e.g. a server) can install this either as a production or development dependency:

npm install log-process-errors

However, libraries should install this as a development dependency:

npm install -D log-process-errors

This is because logging is modified globally and libraries users might not expect this side-effect. Also, this might lead to conflicts between libraries.

This package works in Node.js >=18.18.0.

This is an ES module. It must be loaded using an import or import() statement, not require(). If TypeScript is used, it must be configured to output ES modules, not CommonJS.

API

logProcessErrors(options?)

options object?
Return value: () => void

Start handling process errors.

import logProcessErrors from 'log-process-errors'
logProcessErrors(options)

The return value restores Node.js default behavior.

const restore = logProcessErrors(options)
restore()

Options

exit

Type: boolean

Whether to exit the process on uncaught exceptions or unhandled promises.

This is false by default if other libraries are listening to those events, so they can perform the exit instead. Otherwise, this is true.

If some tasks are still ongoing, the exit waits for them to complete up to 3 seconds.

onError

Type: (error, event) => Promise<void> | void
Default: console.error(error)

Function called once per process error. Duplicate process errors are ignored.

// Log process errors with Winston instead
logProcessErrors({
  onError: (error, event) => {
    winstonLogger.error(error.stack)
  },
})

error

Type: Error

The process error. This is guaranteed to be a normalized error instance. A short description of the event is also appended to its message.

event

Type: Event

Process event name among: 'uncaughtException', 'unhandledRejection', 'rejectionHandled', 'warning'.

Related projects

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

Thanks go to our wonderful contributors:


ehmicky

💻 🎨 🤔 📖

Steven Vachon

💬

Hongarc

📖 💻

Andy Brenneke

🐛

Current Tags

  • 12.0.0                                ...           latest (a year ago)

86 Versions

  • 6.2.0                                ...           4 years ago
  • 5.1.2                                ...           5 years ago
  • 6.1.1                                ...           5 years ago
  • 5.1.1                                ...           5 years ago
  • 5.1.0                                ...           5 years ago
  • 6.1.0                                ...           5 years ago
  • 6.0.1                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.0.3                                ...           5 years ago
  • 5.0.2                                ...           5 years ago
  • 5.0.1                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 4.1.1                                ...           6 years ago
  • 4.1.0                                ...           6 years ago
  • 4.0.0                                ...           6 years ago
  • 3.4.2                                ...           6 years ago
  • 3.4.0                                ...           6 years ago
  • 3.3.0                                ...           6 years ago
  • 3.2.3                                ...           6 years ago
  • 3.2.2                                ...           6 years ago
  • 3.2.1                                ...           6 years ago
  • 3.2.0                                ...           6 years ago
  • 3.1.3                                ...           6 years ago
  • 3.1.2                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.14.2                                ...           6 years ago
  • 0.14.1                                ...           6 years ago
  • 0.14.0                                ...           6 years ago
  • 0.13.21                                ...           6 years ago
  • 0.13.20                                ...           6 years ago
  • 0.13.19                                ...           6 years ago
  • 0.13.17                                ...           6 years ago
  • 0.13.16                                ...           6 years ago
  • 0.13.15                                ...           6 years ago
  • 0.13.14                                ...           6 years ago
  • 0.13.13                                ...           6 years ago
  • 0.13.12                                ...           6 years ago
  • 0.13.11                                ...           6 years ago
  • 0.13.9                                ...           6 years ago
  • 0.13.6                                ...           6 years ago
  • 0.13.2                                ...           6 years ago
  • 0.13.1                                ...           6 years ago
  • 0.13.0                                ...           6 years ago
  • 0.12.1                                ...           6 years ago
  • 0.12.0                                ...           6 years ago
  • 0.11.7                                ...           6 years ago
  • 0.11.6                                ...           6 years ago
  • 0.11.3                                ...           6 years ago
  • 0.11.2                                ...           6 years ago
  • 0.11.0                                ...           6 years ago
  • 0.11.1                                ...           6 years ago
  • 0.10.0                                ...           6 years ago
  • 0.9.1                                ...           6 years ago
  • 0.9.0                                ...           6 years ago
  • 0.8.0                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 12.0.0                                ...           a year ago
  • 11.0.1                                ...           2 years ago
  • 11.0.0                                ...           2 years ago
  • 10.2.0                                ...           2 years ago
  • 10.1.1                                ...           2 years ago
  • 10.1.0                                ...           2 years ago
  • 10.0.0                                ...           2 years ago
  • 9.4.0                                ...           2 years ago
  • 9.3.0                                ...           2 years ago
  • 9.2.0                                ...           2 years ago
  • 9.1.0                                ...           2 years ago
  • 9.0.0                                ...           3 years ago
  • 8.0.0                                ...           3 years ago
  • 7.0.1                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.3.0                                ...           4 years ago
  • 0.7.0                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (11)
Dependents (1)

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