Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)12k · #11570

node-inspect-debugger

Skill này làm gì

Skill này dạy agent cách tìm lỗi trong chương trình Node.js bằng trình gỡ lỗi tích hợp và các công cụ liên quan. Dành cho lập trình viên gặp các vấn đề khó tìm như treo, test không ổn định hoặc lỗi bộ nhớ.

Khi nào nên dùng

  • ✓Khi một chương trình Node.js bị treo hoặc hoạt động lạ và nguyên nhân chưa rõ.
  • ✓Khi một bài test không ổn định và bạn cần dừng đúng điểm nó thất bại.
  • ✓Khi bạn cần ảnh chụp bộ nhớ hoặc hồ sơ CPU để tìm phần chậm hoặc rò rỉ của ứng dụng Node.js.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/EKKOLearnAI/ekko-studio/blob/main/packages/ekko-agent/skills/node-inspect-debugger/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Script Node.js của tôi thỉnh thoảng bị treo. Giúp tôi dừng nó đúng dòng và tìm nguyên nhân.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent khởi động chương trình với inspector tích hợp của Node, đặt breakpoint và kiểm tra giá trị ở mỗi điểm dừng. Với các kiểm tra theo script, nó cũng có thể kết nối với inspector qua một cổng cục bộ.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
Câu hỏi thường gặp

Có an toàn không khi để trình gỡ lỗi mở trên mạng?

Skill khuyên gắn inspector vào 127.0.0.1 và tránh để nó lộ ra mọi địa chỉ mạng.

Nó có hoạt động với TypeScript không?

Có. Với source map, breakpoint có thể trỏ đến mã nguồn TypeScript.

Nó có gỡ lỗi tiến trình con không?

Có, nhưng mỗi tiến trình cần một cổng riêng.

Chi tiết

Mô tả gốc của tác giả

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

repo: EKKOLearnAI/ekko-studio

Độ phổ biến

Sao GitHub
12k
Vị trí xếp hạng
#11570
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự