Common helpers available in node:util include:
format,formatWithOptions,inspect, andstripVTControlCharacters;promisify,callbackify,inherits,deprecate, anddebuglog;isDeepStrictEqual,parseArgs,parseEnv, andstyleText;getSystemErrorName,getSystemErrorMessage, andgetSystemErrorMap;getCallSites;- the global
TextEncoderandTextDecoderconstructors.
toUSVString() and the legacy log() helper are present but throw an
implementation error.
Examples
const util = require("node:util");
util.inspect({ a: [1, 2] }); // "{ a: [ 1, 2 ] }"
util.format("%s:%d", "port", 8080); // "port:8080"
util.isDeepStrictEqual({ a: 1 }, { a: 1 }); // trueinspect() handles common containers, typed arrays, buffers, functions,
circular references, promises, and util.inspect.custom. Options including
depth, breakLength, compact, and maxArrayLength are available.
promisify() honors util.promisify.custom.
util.types
The predicate family covers common arrays and views, dates, maps, sets, errors,
promises, proxies, regular expressions, weak collections, boxed primitives,
function kinds, iterators, and typed-array specializations. Not every
Node predicate is present; test for newer predicates such as isCryptoKey
before calling them.