What tools and techniques do you use to debug a Node.js application, from quick checks to stepping through code?
Show the explanation
Model answer. From quickest to most powerful:
- Logging:
console.log/console.errorfor quick checks; in real services a structured logger (pino, winston) with levels and request ids, so problems can be traced in production. - Built-in inspector: start with
node --inspect app.js(or--inspect-brkto pause on the first line), then openchrome://inspect, or attach VS Code's debugger. You get breakpoints, step over/into, the call stack, variable inspection and a console in context. - `debugger;` statements in code pause there when an inspector is attached.
- Watch mode:
node --watchrestarts on file changes while you iterate. - Performance and memory:
node --cpu-prof, heap snapshots in DevTools, or clinic.js to find slow functions, event-loop blocking and memory leaks. - Tests: a failing unit or integration test that reproduces the bug is the most reliable way to fix it and keep it fixed.
Also read stack traces carefully (enable source maps for TypeScript), and check environment variables and configuration, which cause a large share of "works on my machine" bugs.
Original UniCircle question. Last reviewed 22 Oct 2026.
