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

Node.js · Module

util

The node:util module provides built-in helpers for Node.js internals and application code. It includes formatting, inspection, debugging, type checks, and other common utility APIs.

How it works

The node:util module provides general-purpose helpers used by Node.js internals and application or module developers. Its APIs include debugging output, object inspection, formatting, type checks, deprecation wrappers, and promise-to-callback adaptation.

Syntax

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

Returns

A namespace containing Node.js utility APIs.

Key points

  • node:util is a built-in module whose utilities are also useful to application and module developers.
  • The module is appropriate for reusable backend and application code, not only Node.js implementation internals.
  • ES module code can import the module using the node:-prefixed specifier.
  • CommonJS code can load the module with require('node:util').
  • The types export supplies checks for categories of built-in objects.

Common mistakes

  • The module is broad and is not a single-purpose utility; choose the specific exported API that matches the task.
  • Type-checking helpers are exposed through the types namespace or its dedicated subpath, not only through the top-level module.

Example: Inspect an object

import util from 'node:util';

const user = { id: 7, name: 'Ada' };
console.log(util.inspect(user, { colors: false }));

Loads the built-in module and produces a readable debugging representation of an object.

When to use it

Debug object state

Create readable representations of objects while debugging backend code.

Format diagnostic output

Format values for diagnostic messages and logs.

Validate built-in types

Check whether values are instances of built-in Node.js types.

Bridge async API styles

Adapt callback-based and promise-based APIs at integration boundaries.

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

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