Debugging in VS Code
VS Code has a first-class Node debugger built in — set a breakpoint by clicking in the gutter, hit F5, and step through your code with variables, call stack, and a watch panel right beside the source. It's the most productive way most developers debug Node day-to-day. This page covers the zero-config "JavaScript Debug Terminal", launch.json configurations for launching and attaching, debugging TypeScript with source maps, conditional and logpoint breakpoints, and debugging tests — all without leaving the editor.
The fastest start — the JavaScript Debug Terminal
launch.json — launch configuration
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch", // "launch" = VS Code starts the process
"name": "Debug app.js",
"program": "${workspaceFolder}/app.js",
"skipFiles": ["<node_internals>/**"], // don't step into Node core
"env": { "NODE_ENV": "development" },
"console": "integratedTerminal"
}
]
}Attach to an already-running process
.vscode/launch.json — attach configuration
{
"type": "node",
"request": "attach", // "attach" = connect to an existing process
"name": "Attach to :9229",
"port": 9229,
"skipFiles": ["<node_internals>/**"]
}# Start your app with the inspector, then run the "attach" config in VS Code: node --inspect app.js # For containers/remote, map "remoteRoot"/"localRoot" or tunnel port 9229.
Debugging TypeScript with source maps
tsconfig.json — emit source maps so breakpoints map to .ts lines
{ "compilerOptions": { "sourceMap": true, "outDir": "dist" } }launch.json — run TS directly with tsx/ts-node
{
"type": "node",
"request": "launch",
"name": "Debug TS",
"runtimeExecutable": "node",
"runtimeArgs": ["--import", "tsx"], // or use "outFiles" with compiled JS
"program": "${workspaceFolder}/src/index.ts",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}Breakpoint types beyond the basic stop
Type | What it does | Set via |
|---|---|---|
Breakpoint | Pause when this line executes | Click the gutter |
Conditional | Pause only when an expression is true | Right-click gutter → expression (e.g. |
Hit count | Pause after the line runs N times | Right-click gutter → hit count |
Logpoint | Log a message without pausing — no code edit | Right-click gutter → logpoint |
Caught/uncaught exceptions | Break the moment an error is thrown | Breakpoints panel checkboxes |
Debugging tests
launch.json — debug the node:test runner (or Jest/Mocha)
{
"type": "node",
"request": "launch",
"name": "Debug tests",
"program": "${workspaceFolder}/node_modules/.bin/jest", // or "--test" with node
"args": ["${fileBasenameNoExtension}", "--runInBand"],
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}