Utilities

util.inspect()

Produces debugging text for a JavaScript value, including bounded nested structures. Its output is intended for people, not a stable serialization format. Do not inspect sensitive payloads or untrusted custom inspection hooks. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].

Formal Syntax & Structure

nodejs syntaxnodejs
util.inspect(object[, options])

Parameters & Attributes

NameTypeDescription
objectanyValue to inspect.
optionsobjectFormatting controls.

Return Value

string

Debug representation.

Working Example

Example Snippetnodejs
import { inspect } from 'node:util';const text = inspect({ a: { b: 1 } }, { depth: 0, colors: false, customInspect: false });console.log(text.includes('[Object]'));
Node.js Reference