skills/node-inspect-debugger/SKILL.md
Use for Node.js debugging that needs inspector access: hidden locals, async hangs, flaky tests, child processes, startup races, memory growth, or CPU hot paths.
Default to node inspect first. Use Chrome DevTools Protocol only when you need scripted breakpoints, automated state capture, heap snapshots, or CPU profiles.
Quick start
node inspect path/to/script.jsnode --inspect-brk --import tsx path/to/script.tskill -SIGUSR1 <pid> then node inspect -p <pid>curl -s http://127.0.0.1:9229/json/list | jqnode --inspect-brk openclaw.mjs ...OPENCLAW_VITEST_MAX_WORKERS=1 node --inspect-brk scripts/run-vitest.mjs <file>Debugger REPL
cont, next, step, out, pausesb('file.js', 42), sb(42), sb('functionName'), breakpoints, cb('file.js', 42)bt, list(8), watch('expr'), exec exprrepl, then evaluate locals directly; Ctrl+C exits repl mode.cont before quitting if the process should continue; otherwise kill.OpenClaw tips
127.0.0.1 inspector binds. Do not expose --inspect=0.0.0.0 unless the network is isolated.--enable-source-maps when useful; node inspect can still show emitted paths.NODE_OPTIONS=--inspect-brk can propagate the inspector, but each child needs its own port./json/list.Programmatic CDP
Install tooling outside the repo unless the project already depends on it:
mkdir -p /tmp/cdp-tools
npm --prefix /tmp/cdp-tools i chrome-remote-interface
NODE_PATH=/tmp/cdp-tools/node_modules node /tmp/cdp-debug.cjs
Minimal driver:
const CDP = require("chrome-remote-interface");
(async () => {
const client = await CDP({ port: 9229 });
const { Debugger, Runtime } = client;
Debugger.paused(async ({ callFrames, reason }) => {
const top = callFrames[0];
console.log("paused", reason, top.url, top.location.lineNumber + 1);
const { result } = await Debugger.evaluateOnCallFrame({
callFrameId: top.callFrameId,
expression: "JSON.stringify({ pid: process.pid })",
});
console.log(result.value ?? result.description);
await Debugger.resume();
});
await Runtime.enable();
await Debugger.enable();
await Debugger.setBreakpointByUrl({ urlRegex: ".*target\\.js$", lineNumber: 41 });
await Runtime.runIfWaitingForDebugger();
})();
Profiles
Profiler, start, wait, stop, write /tmp/profile.cpuprofile, open in Chrome DevTools.HeapProfiler, collect addHeapSnapshotChunk, call takeHeapSnapshot, write /tmp/heap.heapsnapshot.Pitfalls
--inspect does not pause; use --inspect-brk when setup must happen before code runs.9229; use --inspect=0 or a unique port for parallel targets.