Debug Node.js with node inspect, --inspect, breakpoints, CDP, heap, and CPU profiles.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "node-inspect-debugger" 技能: 1. 下载 https://raw.githubusercontent.com/openclaw/openclaw/main/skills/node-inspect-debugger/SKILL.md 2. 保存为 ~/.claude/skills/node-inspect-debugger/SKILL.md 3. 装好后重载技能,告诉我可以用了
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.Summarize CodexBar local cost logs by model for Codex or Claude, including current or full breakdowns.
Edit PDFs with natural-language instructions using the nano-pdf CLI.
Diagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
Notion CLI/API for pages, Markdown content, data sources, files, comments, search, Workers, and raw API calls.
Work with Obsidian vaults using the official obsidian CLI: read/search/create/edit notes, tasks, links, properties, plugins.
Search meme templates, suggest formats, and generate local or hosted image memes.