Utilities

util.formatWithOptions()

Formats values with explicit inspection options. Set colors false for plain logs. Avoid treating this human-oriented output as structured JSON or logging secrets. Tested on Node.js 22.16.0. Example output (one line per entry): ["books: 3"].

Formal Syntax & Structure

nodejs syntaxnodejs
util.formatWithOptions(inspectOptions, format[, ...args])

Parameters & Attributes

NameTypeDescription
inspectOptionsobjectInspection settings.
formatanyFormat string or value.
argsany[]Additional values.

Return Value

string

Formatted text.

Working Example

Example Snippetnodejs
import { formatWithOptions } from 'node:util';console.log(formatWithOptions({ colors: false }, '%s: %d', 'books', 3));
Node.js Reference