0
0
NodejsDebug / FixBeginner · 4 min read

How to Debug Node.js in VS Code: Simple Steps

To debug Node.js in VS Code, open your project and set breakpoints by clicking next to the line numbers. Then, create a launch.json file in the Debug panel to configure the debugger, and start debugging with F5 or the green play button.
🔍

Why This Happens

Many beginners try to debug Node.js code in VS Code without setting up a proper launch configuration or breakpoints. This causes the debugger to not stop where expected or not start at all.

javascript
console.log('Start');

function add(a, b) {
  return a + b;
}

console.log(add(2, 3));
Output
Start 5
🔧

The Fix

Set breakpoints by clicking next to the line numbers where you want the code to pause. Then, create a launch.json file in the Debug panel with the Node.js environment configured. This tells VS Code how to run and debug your app.

json
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/app.js"
    }
  ]
}
🛡️

Prevention

Always create and check your launch.json before debugging. Use breakpoints instead of console.log for better control. Keep VS Code and Node.js updated to avoid compatibility issues.

⚠️

Related Errors

Debugger not stopping at breakpoints: Check if the program path in launch.json is correct.
Cannot connect to debug target: Make sure no other process is using the debug port.
Source maps not working: Enable source maps in your build if using TypeScript or Babel.

Key Takeaways

Set breakpoints in VS Code by clicking next to line numbers before debugging.
Create a proper launch.json file to configure Node.js debugging.
Use the Debug panel's green play button or F5 to start debugging.
Keep your tools updated and verify paths in launch.json to avoid errors.
Use breakpoints over console.log for clearer debugging control.