Debug Node.js with Chrome DevTools
Attach Chrome DevTools debugger to a Node.js process for breakpoints, stepping, profiling, and live memory inspection.
Prerequisites
- -Node.js installed
- -Chrome browser
Steps
Start Node.js with the inspect flag
Launch your application with the --inspect flag to start the V8 debugger listening on port 9229.
Use --inspect-brk to pause execution on the very first line, useful for debugging startup issues.
Open Chrome DevTools for Node
Navigate to the dedicated Node.js debugging page in Chrome to connect to the running process.
Click 'Open dedicated DevTools for Node' for a persistent connection that auto-reconnects on restart.
Set breakpoints in source code
Add debugger statements in your code or set breakpoints directly in the DevTools Sources panel.
Debug with VS Code instead of Chrome
Use VS Code's built-in debugger by attaching to the inspect port for an integrated experience.
Set restart: true so the debugger reconnects automatically when you restart the Node process.
Debug a running process by PID
Attach the debugger to an already-running Node.js process without restarting it.
This sends SIGUSR1 which enables the debugger. On Windows, use: node -e "process._debugProcess(PID)" instead.
Full Script
FAQ
Discussion
Loading comments...