Node Inspect 디버거은(는) 무엇을 하나요?
검사기 접근이 필요한 Node.js 디버깅에 사용합니다: 숨겨진 지역 변수, 비동기 중단, 불안정한 테스트, 자식 프로세스, 시작 레이스, 메모리 증가, CPU 핫 경로.
기본적으로 node inspect를 먼저 사용하세요. 스크립트 중단점, 자동 상태 캡처, 힙 스냅샷, 또는 CPU 프로필이 필요할 때만 Chrome DevTools Protocol을 사용하세요.
빠른 시작
- 진입 시 일시 중지:
node inspect path/to/script.js - TypeScript:
node --inspect-brk --import tsx path/to/script.ts - 기존 PID:
kill -SIGUSR1 <pid>후node inspect -p <pid> - 검사 대상 목록:
curl -s http://127.0.0.1:9229/json/list | jq - OpenClaw CLI 경로:
node --inspect-brk openclaw.mjs ... - OpenClaw 테스트 경로:
OPENCLAW_VITEST_MAX_WORKERS=1 node --inspect-brk scripts/run-vitest.mjs <file>
디버거 REPL
- 계속/단계 실행:
cont,next,step,out,pause - 중단점:
sb('file.js', 42),sb(42),sb('functionName'),breakpoints,cb('file.js', 42) - 검사:
bt,list(8),watch('expr'),exec expr - 현재 스코프:
repl후 지역 변수를 직접 평가;Ctrl+C로 repl 모드 종료. - 안전하게 종료: 프로세스를 계속 실행해야 한다면 종료 전에
cont를 사용; 그렇지 않으면kill.
OpenClaw 팁
127.0.0.1검사기 바인딩을 선호합니다. 네트워크가 격리되지 않은 이상--inspect=0.0.0.0을 노출하지 마십시오.- Vitest의 경우, 하나의 파일을 하나의 워커로 디버그하세요. 단계 실행 중에는 워커 풀을 피하십시오.
- TS 소스 중단점의 경우, 필요할 때
--enable-source-maps를 사용하세요;node inspect는 여전히 방출된 경로를 표시할 수 있습니다. - 자식 프로세스의 경우,
NODE_OPTIONS=--inspect-brk가 검사기를 전파할 수 있지만, 각 자식 프로세스는 고유한 포트가 필요합니다. - 오래 지속되는 게이트웨이 또는 개발 프로세스의 경우,
/json/list로 대상을 확인한 후 PID로 연결하세요.
프로그램 방식 CDP
프로젝트가 이미 의존하지 않는 한, 저장소 외부에 도구를 설치하십시오:
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
최소 드라이버:
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();
})();
프로필
- CPU:
Profiler활성화,start, 대기,stop,/tmp/profile.cpuprofile에 쓰기, Chrome DevTools에서 열기. - 힙:
HeapProfiler활성화,addHeapSnapshotChunk수집,takeHeapSnapshot호출,/tmp/heap.heapsnapshot에 쓰기.
함정
--inspect는 일시 중지하지 않습니다; 코드 실행 전에 설정이 필요한 경우--inspect-brk를 사용하십시오.- 기본 포트는
9229입니다; 병렬 대상에는--inspect=0또는 고유한 포트를 사용하십시오. - 중단점이 누락된 경우, 파일 경로, 소스 맵 동작, 그리고 실행이 이미 해당 줄을 통과했는지 확인하십시오.
- 분리 후 프로세스가 멈춘 것처럼 보이면, 여전히 디버거에서 일시 중지된 상태일 수 있습니다.