How to Create a launch.json to Debug a Node.js App in VS Code
Set up a debug configuration, place a breakpoint, and step through Node.js code so you can inspect variables instead of adding console.log everywhere.
When AI-generated code does not behave, the fastest way to understand why is to pause it mid-run and look at the actual values. VS Code's debugger does exactly that. The configuration lives in a launch.json file. This guide creates one for a Node.js app, sets a breakpoint, and steps through the code while inspecting variables.
What you need
- Node.js installed
- A Node project open in VS Code with an entry file such as index.js
- A few minutes
Step 1: Open the Run and Debug view
Click the Run and Debug icon in the activity bar (a triangle with a bug), or press Ctrl+Shift+D. If you have no debug config yet, you will see a link that says create a launch.json file.
Step 2: Generate the configuration
Click create a launch.json file. VS Code asks which environment to use; choose Node.js. It creates a .vscode/launch.json file with a starter configuration. Edit it so the program field points at your entry file.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch index.js",
"program": "${workspaceFolder}/index.js",
"skipFiles": ["<node_internals>/**"]
}
]
}Step 3: Set a breakpoint
Open the file you want to debug and click in the gutter just left of a line number. A red dot appears, marking a breakpoint. Execution will pause there so you can inspect the program's state at that exact moment.
Step 4: Start debugging
Press F5 or click the green play button at the top of the Run and Debug view. The app runs until it hits your breakpoint, then freezes. The line highlights and a debug toolbar appears with controls to continue, step over, step into, and stop.
Step 5: Inspect and step through
While paused, the Variables panel on the left shows every local value in scope. Hover a variable in the editor to see its value inline. Press F10 to step over one line, F11 to step into a function call, and F5 to continue running. Watch the values change as you step.
Result
You now have a reusable debug configuration. Instead of sprinkling console.log statements, you can pause anywhere, read the real values, and step line by line to find exactly where logic goes wrong.
Watch related tutorials
1:42:18
28:14
41:09
9:47
8:23
52:31