- Breakpoint debugging:
node --inspect app.jsexpose debugger tại port 9229; mởchrome://inspect→ attach.--inspect-brkdừng tại dòng đầu tiên — dùng khi debug initialization code. - VS Code launch.json:
{ type: 'node', request: 'launch', program: '${workspaceFolder}/src/index.ts', runtimeArgs: ['-r', 'ts-node/register'] }— breakpoints trong TypeScript với source maps. - Memory profiling: Chrome DevTools → Memory tab → Heap Snapshot → so sánh 2 snapshots tìm memory leak; retained size cho thấy objects đang giữ gì.
- CPU profiling: DevTools → Performance tab → Record → stress → flame graph, tìm hot functions.
clinic doctor -- node app.js: tự phát hiện event loop delay, I/O issues, memory problems, generate HTML report.0x app.js: interactive CPU flamegraph, hiển thị call stacks chiếm CPU. - Source maps:
sourceMap: truetrong tsconfig để debugger map JS → TS. - Lưu ý:
--inspecttrong production mà expose port ra internet → remote code execution vulnerability; bind tới localhost only.
- Breakpoint debugging:
node --inspect app.jsexposes the debugger on port 9229; openchrome://inspect→ attach.--inspect-brkpauses at the first line — use when debugging initialization code. - VS Code launch.json:
{ type: 'node', request: 'launch', program: '${workspaceFolder}/src/index.ts', runtimeArgs: ['-r', 'ts-node/register'] }— TypeScript breakpoints with source maps. - Memory profiling: Chrome DevTools → Memory tab → Heap Snapshot → compare two snapshots to find memory leaks; retained size shows what objects are holding onto.
- CPU profiling: DevTools → Performance tab → Record → stress the app → flame graph to find hot functions.
clinic doctor -- node app.js: auto-detects event loop delay, I/O issues, memory problems, generates an HTML report.0x app.js: interactive CPU flamegraph showing call stacks consuming CPU. - Source maps:
sourceMap: truein tsconfig lets the debugger map JS → TS.
Pitfall: --inspect in production with the port exposed to the internet → remote code execution vulnerability; bind to localhost only.