跳到正文
Skillpedia
API 与服务器(后端)12k · #11570

node-inspect-debugger

它能做什么

该技能教智能体如何使用内置调试器及相关工具,查找 Node.js 程序中的缺陷。适用于遇到难以找到的问题的开发者,例如程序卡死、测试不稳定或内存问题。

适用场景

  • ✓当 Node.js 程序卡死或行为异常,而原因不明确时。
  • ✓当测试不稳定,你需要在失败的确切位置暂停时。
  • ✓当你需要内存快照或 CPU 分析,以找出 Node.js 应用中缓慢或泄漏的部分时。

技能链接

https://github.com/EKKOLearnAI/ekko-studio/blob/main/packages/ekko-agent/skills/node-inspect-debugger/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/EKKOLearnAI/ekko-studio/blob/main/packages/ekko-agent/skills/node-inspect-debugger/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的 Node.js 脚本有时会卡住。请帮我在正确的行暂停它,并找出原因。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会使用 Node 内置的检查器启动程序,设置断点,并在每次暂停时检查变量值。对于脚本化的检查,它也可以通过本地端口连接到检查器。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Node Inspect Debugger

Use when Node.js debugging requires hidden locals, async hangs, flaky tests, child processes, startup races, memory analysis, or CPU profiling.

Default to node inspect first. Use Chrome DevTools Protocol only for scripted breakpoints, automated state capture, heap snapshots, or CPU profiles.

Quick start

node inspect path/to/script.js
node --inspect-brk --import tsx path/to/script.ts
kill -SIGUSR1 <pid>
node inspect -p <pid>
curl -s http://127.0.0.1:9229/json/list | jq

For a test runner such as Vitest, debug one file with one worker and avoid worker pools while stepping.

Debugger REPL

  • Continue and step: cont, next, step, out, pause.
  • Breakpoints: sb('file.js', 42), sb(42), sb('functionName'), breakpoints, cb('file.js', 42).
  • Inspect: bt, list(8), watch('expr'), exec expr.
  • Current scope: enter repl, evaluate locals, then press Ctrl+C to exit REPL mode.
  • Exit safely: use cont before quitting if the process should keep running; otherwise use kill.

Safe setup

  • Prefer 127.0.0.1 inspector binds. Do not expose --inspect=0.0.0.0 unless the network is isolated.
  • Use --enable-source-maps when TypeScript source breakpoints need it.
  • NODE_OPTIONS=--inspect-brk can propagate the inspector to child processes, but each process needs a unique port.
  • For a long-lived service, confirm the PID and /json/list target before attaching.

Programmatic CDP

Install temporary tooling outside the project unless it is already a dependency:

mkdir -p /tmp/cdp-tools
npm --prefix /tmp/cdp-tools install 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

  • CPU: enable Profiler, start, wait, stop, write a .cpuprofile, then open it in Chrome DevTools.
  • Heap: enable HeapProfiler, collect addHeapSnapshotChunk, call takeHeapSnapshot, then write a .heapsnapshot.

Pitfalls

  • --inspect does not pause; use --inspect-brk when startup code matters.
  • Port 9229 is the default; use --inspect=0 or a unique port for parallel targets.
  • If a breakpoint misses, confirm the path, source maps, and whether execution already passed the line.
  • A process that appears frozen after detach may still be paused in the debugger.
常见问题

在网络上让调试器保持开启安全吗?

该技能建议把检查器绑定到 127.0.0.1,并避免将其暴露给所有网络地址。

它支持 TypeScript 吗?

支持。配合 source map,断点可以指向 TypeScript 源代码。

它能调试子进程吗?

能,但每个进程都需要自己的端口。

详情

作者的原始描述

Debug Node.js with node inspect, inspector attach, breakpoints, Chrome DevTools Protocol, heap snapshots, and CPU profiles.

repo: EKKOLearnAI/ekko-studio

热度

GitHub 星标
12k
排名
#11570
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能