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
| Name | Type | Description |
|---|---|---|
| inspectOptions | object | Inspection settings. |
| format | any | Format string or value. |
| args | any[] | 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));