What is the util module in Node.js?
Why Interviewers Ask This
This is a classic screening question for Node.js roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
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.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.
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?