Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Node.js · Module

node:util

The node:util module provides general-purpose helpers used by Node.js internals and application developers. Its APIs cover debugging inspection, formatting, type checks, and other runtime utilities.

How it works

The module exposes general-purpose helpers for formatting, inspection, debugging, type checks, and other runtime-oriented tasks. Import it with the node:util specifier, then call the relevant utility; for example, inspect() synchronously converts a value into a debug-oriented string.

Syntax

import util from 'node:util';
const util = require('node:util');

Parameters

NameTypeDescription
objectanyThe value to render or examine, depending on the selected utility.
optionsObjectOptional settings that alter inspection output.

Returns

The module provides utility-specific results; util.inspect() returns a string representation of the supplied object.

Key points

  • node:util contains reusable runtime helpers that support Node.js internals and application code.
  • Its audience includes ordinary application and package developers, not only Node.js core.
  • inspect() turns a value into a human-readable debugging string.
  • util.types offers predicates for recognizing particular built-in object kinds.
  • CommonJS code can reach type predicates from either the main module's types property or its subpath.

Common mistakes

  • Do not parse inspect() output or use it as a stable serialization format.
  • Avoid using inspect() in latency-sensitive paths for large or complex values.
  • Use the documented types entry points when importing built-in-object predicates.

Example: Inspect a value

import util from 'node:util';

const value = { user: 'Ada', roles: ['admin'] };
console.log(util.inspect(value, { colors: false, depth: null }));

Creates a readable debugging representation of a nested value.

When to use it

Debug runtime values

Need a readable representation of an object while diagnosing behavior.

Perform built-in type checks

Need to identify a specific built-in object type safely.

Build backend utilities

Need shared Node.js helpers for formatting or adapting callback-based APIs.

Interview questions

QHow do you load the node:util module, and what is it for?

Import the module with node:util, using either ES modules or CommonJS. The module contains utilities used by Node internals and application developers.

Follow-up: How should inspect() output be used? Only for human-oriented debugging, because its format is not a programmatic contract.

QWhat does util.inspect() do?

util.inspect(object, options) returns a string representation intended for debugging. Options can control aspects of formatting, such as recursion depth and color output.

Follow-up: Why should the result not be persisted as structured data? Its output may change, so it is unsuitable as a stable serialization format.

QWhat does util.types provide?

util.types supplies predicates for identifying different kinds of built-in objects. It is available from the main module or through the node:util/types subpath.

Follow-up: When is this preferable to generic checks? When code needs to distinguish specific built-in runtime types rather than merely test broad JavaScript categories.

  • util.format()
  • util.inspect()
  • util.debuglog()
  • util.types
  • util.promisify()
  • util.callbackify()

Source: Util | Node.js v26.11.1 Documentation. Checked 2026-10-15.