Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/node/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Node.js provides powerful debugging capabilities through the V8 Inspector protocol, enabling you to debug applications using Chrome DevTools, VS Code, and other debugging clients.Command-Line Debugger
Node.js includes a built-in command-line debugging utility for simple stepping and inspection.Starting the Debugger
Start Node.js with theinspect argument:
The debugger automatically breaks on the first executable line.
Resume on Start
To run until the firstdebugger statement instead of breaking immediately:
Debugger Commands
Stepping Commands
Continue execution
Step to next line
Step into function
Step out of function
Pause running code
Breakpoint Commands
Information Commands
Print backtrace of current execution frame
List source code with 5 line context
Add expression to watch list
List all watchers and their values
Open debugger REPL for evaluation
Execute expression and print value
Using Watchers
Watch expression values at each breakpoint:REPL Mode
Evaluate code in the debugging context:Ctrl+C to exit REPL mode.
V8 Inspector Protocol
The V8 Inspector enables powerful debugging with Chrome DevTools and other clients.Inspector Flags
- --inspect
- --inspect-wait
- --inspect-brk
Start with inspector enabled. Code runs immediately.Output:
Custom Port
Specify a custom debugging port:Chrome DevTools Integration
Connecting Chrome DevTools
DevTools Features
- Sources Panel: Set breakpoints, step through code
- Console: Evaluate expressions in the current context
- Profiler: Record CPU profiles
- Memory: Take heap snapshots
- Network: Inspect network requests (with
--experimental-network-inspection)
VS Code Debugging
Launch Configuration
Create.vscode/launch.json:
Debug Current File
Debug with Arguments
Using the Inspector API
Programmatically control the inspector from your code.Opening the Inspector
CPU Profiling
Heap Snapshots
Taking Heap Snapshots from Debugger
From the command-line debugger:Debugging Best Practices
Use debugger Statement
Use debugger Statement
Add
debugger; statements in your code to create breakpoints:Enable Source Maps
Enable Source Maps
For TypeScript or transpiled code, enable source maps:
Skip Node Internals
Skip Node Internals
Focus on your code by skipping Node.js internals in VS Code:
Use Conditional Breakpoints
Use Conditional Breakpoints
Break only when specific conditions are met:
Remote Debugging
SSH Tunneling
Debug a remote Node.js application securely:localhost:9229.
Troubleshooting
Debugger Won't Connect
Debugger Won't Connect
- Verify the port is not blocked by firewall
- Check if another process is using port 9229
- Ensure you’re connecting to the correct IP/port
Source Maps Not Working
Source Maps Not Working
- Enable source maps:
--enable-source-maps - Ensure source map files (.map) are present
- Check sourceRoot in tsconfig.json
Breakpoints Not Hitting
Breakpoints Not Hitting
- Verify code is actually being executed
- Check if using —inspect-brk for early breakpoints
- Ensure file path matches exactly
Next Steps
Performance
Profile and optimize your code
Testing
Write and run tests