VS Code: Interactive Debugging & launch.json
Complete guide to VS Code debugging, breakpoints, conditional breakpoints, logpoints, watch variables, call stack inspection, and launch.json configurations.
VS Code features an interactive debugger for Node.js, Next.js, TypeScript, Python, and browser runtimes, replacing console.log debugging with step execution, heap inspection, and live expression watches.
Debugging Workflow
- Set Breakpoint: Click the left gutter next to any line number (red dot appears).
- Launch Session: Press F5 to start debugging.
- Inspect Execution State:
- Variables: Inspect local and global closure scopes.
- Watch: Add custom expressions to evaluate on every step (e.g.
req.headers.authorization). - Call Stack: Trace the execution path through parent callers.
- Debug Console: Interactive REPL in the context of the current paused frame.
Debug Actions Toolbar
| Icon / Key | Action | Description |
|---|---|---|
| F5 | Continue | Resumes execution until the next breakpoint |
| F10 | Step Over | Executes the current line and pauses at the next line |
| F11 | Step Into | Enters inside the function called on the current line |
| Shift + F11 | Step Out | Finishes current function and returns to caller |
| Cmd/Ctrl + Shift + F5 | Restart | Restarts the debug session |
| Shift + F5 | Stop | Terminates the debugger |
Configuring .vscode/launch.json
Create .vscode/launch.json to define repeatable debug configurations:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Next.js App Router (Full Stack)",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev"
},
{
"name": "Debug Current TypeScript File (tsx)",
"type": "node",
"request": "launch",
"runtimeExecutable": "tsx",
"args": ["${file}"],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "**/node_modules/**"]
},
{
"name": "Attach to Running Node Process",
"type": "node",
"request": "attach",
"port": 9229,
"restart": true
}
]
}Conditional Breakpoints & Logpoints
Right-click the gutter next to a line number:
- Add Conditional Breakpoint: Triggers only when a condition matches (e.g.
items.length === 0). - Add Logpoint: Prints a message to Debug Console without halting execution (e.g.
User logged in with ID: {user.id}).
Related Guides
VS Code: Custom Code Snippets
Complete guide to authoring custom VS Code snippets for TypeScript, React, and Next.js, tab stops ($1, $2), placeholders, and variables.
VS Code: Git & Version Control Integration
Complete guide to VS Code Git integration, Source Control panel, stage ranges, 3-way merge conflict editor, timeline view, and branch management.