Node.js module

util

The 'node:util' module provides utility functions for debugging and supporting internal Node.js operations. It includes util.format, util.callbackify, util.promisify, and util.inspect.

These helpers simplify error handling, convert callbacks to promises, format strings, and inspect objects with configurable depth and styling.

Works in Bun · notes

Most utility functions are implemented. Missing specific functions related to call sites, system errors, and transferable AbortSignals/Controllers.

Functions 23

  • util.aborted()

    Listens to abort event on the provided signal and returns a promise that resolves when the signal is aborted.

  • util.callbackify()

    Takes an async function (or a function that returns a Promise) and returns a function following the error-first callback style, i.e.

  • util.convertProcessSignalToExitCode()

    The util.convertProcessSignalToExitCode() method converts a signal name to its corresponding POSIX exit code.

  • util.debuglog()

    The util.debuglog() method is used to create a function that conditionally writes debug messages to stderr based on the existence of the NODE_DEBUG environment v…

  • util.diff()

    util.diff() compares two string or array values and returns an array of difference entries.

  • util.format()

    The util.format() method returns a formatted string using the first argument as a printf-like format string which can contain zero or more format specifiers.

  • util.formatWithOptions()

    This function is identical to format, except in that it takes an inspectOptions argument which specifies options that are passed along to inspect.

  • util.getCallSites()

    Returns an array of call site objects containing the stack of the caller function.

  • util.getSystemErrorMap()

    Returns a Map of all system error codes available from the Node.js API.

  • util.getSystemErrorMessage()

    Returns the string message for a numeric error code that comes from a Node.js

  • util.getSystemErrorName()

    Returns the string name for a numeric error code that comes from a Node.js API.

  • util.inherits()

    Usage of util.inherits() is discouraged.

  • util.inspect()

    The util.inspect() method returns a string representation of object that is intended for debugging.

  • util.isDeepStrictEqual()

    Returns true if there is deep strict equality between val1 and val2.

  • util.parseArgs()

    Provides a higher level API for command-line argument parsing than interacting with process.argv directly.

  • util.parseEnv()

    Stability: 1.1 - Active development

  • util.promisify()

    Takes a function following the common error-first callback style, i.e.

  • util.setTraceSigInt()

    Enable or disable printing a stack trace on SIGINT.

  • util.stripVTControlCharacters()

    Returns str with any ANSI escape codes removed.

  • util.styleText()

    This function returns a formatted text considering the format passed for printing in a terminal.

  • util.toUSVString()

    Returns the string after replacing any surrogate code points (or equivalently, any unpaired surrogate code units) with the

  • util.transferableAbortController()

    Creates and returns an AbortController instance whose AbortSignal is marked as transferable and can be used with structuredClone() or postMessage().

  • util.transferableAbortSignal()

    Marks the given AbortSignal as transferable so that it can be used withstructuredClone() and postMessage().

Classes 2

Interfaces 23

Types 9

Variables 2

Namespaces 2

Other 1