Node.js Inspect Debugger

389549 89545 Updated: 2026-07-15 13:48:52

Node.js Inspect Debugger is a powerful tool for debugging Node.js applications. It allows developers to connect to running Node.js processes via Chrome DevTools or other compatible debugging clients for breakpoint setting, variable inspection, call stack analysis, and performance profiling. Built on Node.js's built-in inspect protocol, it supports remote debugging, multi-process debugging, memory snapshots, and more, making it suitable for troubleshooting and performance optimization in development, testing, and production environments.

Install
bunx skills add https://github.com/openclaw/openclaw.git --skill node-inspect-debugger
Skill Details readonly

1. Skill Overview

This skill applies to scenarios requiring Node.js debugging with Inspector privileges. It defaults to the node inspect CLI debugger, and only leverages the Chrome DevTools Protocol (CDP) when scripted breakpoints, automated state capture, heap snapshots, or CPU profiling are required.

2. Core Capabilities

2.1 Quick Debug Session Startup

Multiple ways to launch debug sessions for different scenarios:
Scenario Command  
Pause at entry for debugging node inspect path/to/script.js  
TypeScript debugging node --inspect-brk --import tsx path/to/script.ts  
Attach to a running process kill -SIGUSR1 <PID> then node inspect -p <PID>  
List inspectable debug targets `curl -s http://127.0.0.1:9229/json/list jq`
OpenClaw CLI debugging node --inspect-brk openclaw.mjs ...  
Single-file Vitest debugging OPENCLAW_VITEST_MAX_WORKERS=1 node --inspect-brk scripts/run-vitest.mjs <file>  

2.2 Debugger REPL Commands

Interactive debugging commands available within a debug session:
Command Purpose
cont, next, step, out, pause Continue, step over, step into, step out, pause execution
sb('file.js', 42), sb(42), sb('functionName') Set breakpoint: file + line number, line number in current file, function name
breakpoints, cb('file.js', 42) List all breakpoints, clear specified breakpoint
bt Print full call backtrace
list(8) Show source code around current execution position
watch('expr') Watch the value of an expression
exec expr Evaluate arbitrary expressions in current scope
repl Enter REPL mode to inspect local variables; press Ctrl+C to exit
Exit rule: Run cont first before exiting if the process should keep running; terminate directly otherwise.

2.3 OpenClaw Project Debugging Best Practices

Optimized debugging guidance tailored to the OpenClaw codebase:
  • Inspector binding rule: Bind exclusively to 127.0.0.1 by default. Avoid --inspect=0.0.0.0 unless running within an isolated private network.
  • Vitest debugging: Use single-worker mode for single-file test debugging to avoid worker pool interference during stepping.
  • TypeScript source breakpoints: Enable --enable-source-maps to render original TS file paths inside node inspect.
  • Child process debugging: NODE_OPTIONS=--inspect-brk propagates inspector flags to child processes, but each subprocess requires a unique dedicated port.
  • Long-lived daemons: Attach via PID; always list targets via /json/list to confirm the correct debug endpoint first.

2.4 Programmatic CDP (Chrome DevTools Protocol)

Use CDP for automated scripted breakpoint logic and unattended state capture:
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();
})();
Temporary CDP tool installation outside repo source tree:
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

2.5 CPU & Heap Memory Profiling via CDP

CDP-powered performance profiling workflows:
Profiling Type Operation Flow
CPU Profiling Enable Profiler → Start capture → Wait for workload → Stop capture → Write output to /tmp/profile.cpuprofile for inspection in Chrome DevTools
Heap Snapshot Enable Heap Profiler → Subscribe to chunk events → Trigger snapshot capture → Save full snapshot file to /tmp/heap.heapsnapshot

3. Primary Use Cases

  1. Debug hidden variables & asynchronous hangs — Trace elusive async call chains and closure-scoped state
  2. Flaky test troubleshooting — Isolate root causes of intermittent test failures via breakpoints and single-step execution
  3. Child process & startup race condition debugging — Diagnose initialization ordering issues in multi-process architectures
  4. Memory growth analysis — Compare sequential heap snapshots to identify memory leaks
  5. CPU hot path profiling — Locate performance bottlenecks via CPU profiling traces
  6. Dedicated OpenClaw debugging — Debug OpenClaw CLI entrypoints and isolated Vitest test files

4. Critical Guiding Principles

  1. Default to node inspect: Only use CDP when automated scripting logic is mandatory
  2. Avoid public inspector binding --inspect=0.0.0.0: Introduces severe security risks without isolated network segmentation
  3. Single-worker Vitest mode required for stepping: Worker pools disrupt predictable single-step debugging
  4. Independent ports for child processes: NODE_OPTIONS=--inspect-brk propagates flags, but each subprocess needs a unique port
  5. --inspect vs --inspect-brk: --inspect does not pause on launch; use --inspect-brk to halt execution before application logic runs
  6. Default inspector port 9229: Use --inspect=0 or custom unique ports for parallel simultaneous debug sessions
  7. Breakpoint misfire troubleshooting: Validate file path resolution, source map generation, and whether execution has already passed the target line
  8. Frozen process handling: If a process appears unresponsive after detaching, it may still be suspended at a debugger breakpoint

Summary

Node Inspect Debugger is a dedicated skill for deep Node.js debugging within the OpenClaw project. It provides two core tooling paths — the lightweight node inspect CLI debugger and fully programmable Chrome DevTools Protocol (CDP) — covering debugging scenarios including hidden closure variables, async stalls, flaky tests, child process race conditions, memory bloat analysis, and CPU bottleneck profiling. It delivers a complete workflow from one-click debug startup to automated programmatic tracing, with specialized debugging guidance built for OpenClaw CLI and Vitest test suites.