Util

Node.js util module — general-purpose utility functions. Includes string formatting, object inspection, promisification, and type checks.

Module: node:util Support: Experimental Since: 1.1.0 Docs: Node.js Docs See also: https://nodejs.org/api/util.html

21 members: 19 supported, 2 undocumented

Static Methods

🟢 format(args)
Formats a string using printf-style substitution patterns (%s, %d, %o, etc.).
🟢 formatWithOptions(inspectOptions, args)
Like format(), but accepts an explicit util.inspect options object for the first argument.
🟢 inspect(value, options)
Returns a string representation of an object for debugging.
🟢 promisify(original)
Wraps a callback-based function so it returns a Promise.
🟢 inherits(constructor, superConstructor)
Sets up prototype inheritance between a constructor and a superclass.
🟢 isDeepStrictEqual(val1, val2, skipPrototype)
Returns true if two values are deeply equal using the strict equality algorithm.
🟢 deprecate(fn, msg, code, options)
Wraps a function to emit a deprecation warning when called.
🟢 debuglog(section)
Returns a logging function that writes to stderr only if the NODE_DEBUG env variable includes section.
🟢 callbackify(original)
Wraps an async function (or a function that returns a Promise) so it follows
🟢 getSystemErrorName(err)
Returns the string name for a numeric error code (the errno value).
🟢 getSystemErrorMessage(err)
Returns the string message for a numeric error code (the errno value).
🟢 getSystemErrorMap()
Returns a Map of all system error codes to [name, message] pairs.
🟢 toUSVString(string)
Returns a string after replacing any lone surrogates with the Unicode replacement character U+FFFD.
🟢 stripVTControlCharacters(str)
Removes ANSI escape codes (including color and cursor movement) from a string.
🟢 styleText(format, text, options)
Formats text with ANSI styling for terminal output.
🟢 getCallSites(frameCount, options)
Returns an array of call site objects representing the current call stack.
🟢 parseEnv(content)
Parses a .env file content string into a key-value object.
🟢 log(args)
Writes a formatted timestamp + message to stdout (similar to console.log but with a timestamp).

Properties

🟢 types
Writes a formatted timestamp + message to stdout (similar to console.log but with a timestamp).
⚪ TextEncoder
Object with type-checking predicates (e.g. util.types.isDate, util.types.isMap). @compat elide Full
⚪ TextDecoder
The WHATWG TextEncoder class. @compat elide Full

---

Details

inherits(constructor, superConstructor)

static inherits(constructor: object, superConstructor: object)

static inherits(constructor: object, superConstructor: object)

Sets up prototype inheritance between a constructor and a superclass.
ParameterTypeDescription
constructorobjectThe child constructor
superConstructorobjectThe parent constructor
> Known issue: Deprecated; use ES6 class extends syntax instead