Debugging with Chrome DevTools
Because Node's Inspector speaks the Chrome DevTools Protocol, you can attach the full Chrome DevTools UI to a Node process — the same Sources, Console, Memory, and Performance panels you'd use for a web page, now pointed at your server code. This is especially valuable for the things a code editor's debugger doesn't do as well: CPU profiling with flame charts and heap snapshots for memory analysis. This page covers connecting via chrome://inspect, the panels, and using DevTools to find performance and memory problems.
Connecting DevTools to Node
# 1. Start Node with the inspector: node --inspect app.js # or --inspect-brk to pause on the first line # 2. In Chrome, open: chrome://inspect # 3. Under "Remote Target", click "inspect" on your Node process. # (Or click the green Node.js logo for a dedicated DevTools window.)
Debugger listening on ws://127.0.0.1:9229/8f3a... For help, see: https://nodejs.org/en/docs/inspector
The panels that matter for Node
Panel | Use for |
|---|---|
Sources | Breakpoints, step-through, watch, call stack, scope inspection |
Console | A REPL in the current breakpoint scope — evaluate any expression |
Memory | Heap snapshots & allocation timelines — find memory leaks |
Performance | CPU profile with flame charts — find hot functions & blocked event loop |
CPU profiling — find what's slow
Open the Performance panel → click Record → exercise the slow operation → Stop.
DevTools shows a flame chart: width = time spent, so the widest bars are your hottest code paths.
Look for wide, flat plateaus — a single synchronous function eating CPU and blocking the event loop.
Switch to the Bottom-Up / Call Tree view to rank functions by self-time vs total time.
Alternatively capture a profile programmatically with the
node --cpu-profflag and load the.cpuprofilefile.
# Write a CPU profile to disk without DevTools, then open it in the Performance panel: node --cpu-prof --cpu-prof-dir=./profiles app.js # Produces ./profiles/CPU.<date>.cpuprofile → drag into DevTools Performance tab
Heap snapshots — find memory leaks
Open the Memory panel → choose Heap snapshot → Take snapshot.
Take a second snapshot after running the suspected leaking operation many times.
Use the Comparison view to see which object types grew between snapshots — that growth is your leak.
Click a growing object and inspect Retainers — the reference chain keeping it alive (the cause).
The Allocation instrumentation on timeline view shows allocations live as you interact.