Debugging Node — --inspect, breakpoints and DevTools¶
Level: 201 · for readers who have debugged with console.log alone
Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.
One line: debugger; is a breakpoint only while a debugger is attached — otherwise Node runs straight past it; node --inspect opens one on ws://127.0.0.1:9229 and keeps running, and --inspect-brk waits there before the first line.
Keywords: --inspect, --inspect-brk, debugger, node inspect, chrome://inspect
What the finished page will answer¶
- What does a
debugger;statement do with no debugger attached, and what undernode inspect? - What does
--inspectprint, on which address and port, and why is--inspect=0.0.0.0dangerous? - Where does
--inspect-brkstop, and what does the program do until a debugger attaches? - How do you step through a script with
node inspectalone:cont,next,exec sum? - How do VS Code and Zed attach to a process started with
--inspect, and what doeschrome://inspectlist?
Examples it will need¶
-
debugging_node_debugger_statement_sh.sh— adebugger;statement run without a debugger, the--inspectbanner with its UUID masked, and--inspect-brkwaiting until a 3-second timeout -
debugging_node_inspect_cli_sh.sh— anode inspectsession fed from stdin: the stop atdebugger;,exec sumprinting 0.30000000000000004, then the program's own output
See also¶
- Stack traces — the call stack a breakpoint shows live
- Editor setup — the editors that attach to port 9229
- Measuring memory — heap snapshots through the same inspector
- Running a file with Node — the other flags
nodetakes - C: What the debugger records ↗ — what a native debugger records, in C