What is the util module in Node.js?
Answer
The util module provides utility functions for internal Node.js use that are also useful for application development. Key features: util.promisify(fn) — converts a callback-style function (following error-first convention) to return a Promise: const readFile = util.promisify(fs.readFile); then use with async/await; util.callbackify(fn) — the reverse; util.inspect(object, options) — returns a string representation of an object for debugging (used internally by console.log); util.format(format, ...args) — formatted string (like printf); util.inherits(constructor, superConstructor) — prototype-based inheritance (legacy, pre-class syntax); util.types — type checks like util.types.isPromise(), util.types.isRegExp(). util.promisify is particularly useful for modernizing older callback-based APIs and third-party libraries that haven't yet been updated to return Promises.
Previous
What is the query string in a URL and how do you access it in Express?
Next
What is the crypto module in Node.js?