Question presented to candidate: "Beyond scattering console.log statements everywhere, what tools does Node.js actually give you for debugging, and when would you reach for each?"
What a strong answer should cover:
console.logis the simplest, most common tool, but Node'sconsoleobject offers more targeted variants:console.error/console.warn(separate output stream, useful for log-level filtering),console.table(tabular display for arrays of objects), and 📌console.trace, which prints a message plus a real call stack — genuinely useful for answering "who called this, and through what path" without manually threading that information through.util.inspect(whichconsole.loguses internally for non-string values) gives fine control over how a nested object is printed —{ depth: null }in particular removes the default depth limit, which otherwise silently truncates a deeply nested object's printed output.node --inspect(or--inspect-brk, which pauses execution before the first line) starts Node with a debugging protocol server, connectable from Chrome DevTools or VS Code's built-in debugger — enabling real breakpoints, step-through execution, and live variable inspection, categorically more powerful than console statements.- The
debugger;statement is a genuine breakpoint in code, honored only when a debugger client is actually attached (via--inspect) — otherwise it does nothing at all, a common point of confusion for engineers new to it. - For production debugging where attaching an interactive debugger is impractical or unsafe, structured logging (covered fully in its own dedicated question) and heap snapshots/CPU profiles (also covered in their own dedicated questions) are the standard tools — a precise answer distinguishes "debugging a local reproduction" from "diagnosing a live production issue," since the toolset genuinely differs between them.
node --trace-warnings/process.on("warning", ...)surface Node's own internal deprecation/warning signals, which are easy to miss silently in normal output otherwise.
Clarifying questions expected:
- "Is this a local reproduction, or a live production issue?" — the right toolset differs significantly.
- "Interactive step-through debugging, or understanding a specific already-observed symptom (a leak, a slow request)?" — decides between
--inspectand the profiling/logging tools.
Code / implementation expected: Optional — showing console.trace's actual stack output and util.inspect's depth control directly is a concrete, convincing way to demonstrate real familiarity rather than naming tools abstractly.