Nimble Polyglot Microcosm
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »


2.1.1 • Public • Published

downloads last commit license Coverage Status travis npm node JavaScript Style Guide eslint-config-standard-prettier-fp Gitter

By default Node.js prints uncaughtException, warning and mishandled promises (unhandledRejection, rejectionHandled, multipleResolves) on the console which is very useful. Unfortunately those process errors:

Without log-process-errors:

Screenshot before

log-process-errors fixes those issues:

Screenshot after


npm install -D log-process-errors

This should only be installed as a production dependency for production code (e.g. a web server), not for libraries. This is because logging is modified globally and libraries users might not expect this side-effect. Also this might lead to conflicts between libraries.


There are two ways to load this library. The first is to use the node -r CLI flag:

node -r log-process-errors/register ...

The second is:

const logProcessErrors = require('log-process-errors')

logProcessErrors() should be called as early as possible in the code.

options is an optional object with the following properties:

Custom logging

By default events will be logged to the console using console.error(), console.warn(), etc.

This behavior can be overridden with the log option. For example to log events with Winston instead:

  log(message, level, info) {

The function's arguments are message (string), level (string) and info (object).

If logging is asynchronous, the function should return a promise (or use async/await). This is not necessary if logging is using streams (like Winston).

Duplicate events are only logged once (whether the log option is defined or not).

Log level

The default log level is warn for warning, info for multipleResolves and error for the other events.

This can be overridden by using the level option. It should be an object whose:

  // Use `debug` log level for `multipleResolves` instead of `info`
  level: { multipleResolves: 'debug' },
  // Skip some logs based on a condition
  level: {
    default() {
      if (shouldSkip()) {
        return 'silent'

Log message

A nice-looking and descriptive log message is generated by default.

The message will be colorized unless the option colors is set to false.

The message generation can be overridden by using the message option. It should be a function using info as argument and returning a string.

Event information

The log, level and message options all receive as argument an info object.


Can be "uncaughtException", "unhandledRejection", "rejectionHandled", "multipleResolves" or "warning".



It is usually an Error instance but could be anything.


Boolean indicating whether the promise was initially resolved or rejected. Only defined with multipleResolves.

info.nextValue, info.nextRejected

Like value and rejected but for the second time the promise was resolved/rejected. Only defined with multipleResolves.


Log level. Only defined with the message option.


Chalk instance to colorize strings. Only defined with the message option. Disabled if the colors option is false.

Process exit

The exitOn option specifies which event should trigger process.exit(1):

  • the default value is ["uncaughtException"]. This is the default behavior of Node.js.
  • we recommend using ["uncaughtException", "unhandledRejection"] instead since this will be the future default behavior of Node.js.
  • to prevent any process.exit(1) use []. Recommended if your process is long-running and does not automatically restart on exit.

process.exit(1) will only be fired after successfully logging the event.

Stop logging

Logging can be stopped by firing the function returned by logProcessErrors().

const logProcessErrors = require('log-process-errors')
const stopLogging = logProcessErrors(options)


npm i log-process-errors

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability