- 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.
Pitfall: --inspect trong production mà expose port ra internet → remote code execution vulnerability; bind tới localhost only.