VS Code SetupIntermediate

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.

9 minIntermediate

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.

.vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch index.js",
      "program": "${workspaceFolder}/index.js",
      "skipFiles": ["<node_internals>/**"]
    }
  ]
}
What skipFiles does
The skipFiles line tells the debugger to step over Node's internal modules so you only stop in your own code. Keep it in to avoid jumping into files you did not write.

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.

VS Code - breakpoint set
Explorer
index.js
index.js
1 function total(items) {
2* let sum = 0 // <- breakpoint here
3 for (const i of items) sum += i.price
4 return sum
5 }
A red breakpoint dot in the editor gutter.

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.

VS Code - debug paused
VARIABLES
------------------------------------
Local
sum: 0
items: Array(3)
this: undefined
------------------------------------
CALL STACK total (index.js:2)
The Variables panel while execution is paused.

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

Tags
#debug#nodejs#launch-json#breakpoints