VS Code Setup and WSL2 IntegrationLesson 5.5
How to debug Node.js applications in VS Code with WSL2
launch.json configuration, setting breakpoints, debug console, watch expressions, call stack panel, attaching to running process, nodemon with debugger, common debug configs
Debugging Node.js in VS Code
VS Code debugger connects to Node.js running inside WSL2 seamlessly. You set breakpoints in the editor, run the program, and execution pauses at the line you chose.
Create a launch configuration
Press Ctrl+Shift+D to open the Run and Debug panel, click create a launch.json file, and select Node.js:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch app",
"program": "${workspaceFolder}/src/index.js",
"console": "integratedTerminal"
}
]
}Debugging with nodemon
{
"type": "node",
"request": "launch",
"name": "Launch with nodemon",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/src/index.js",
"restart": true,
"console": "integratedTerminal"
}Workflow
Click the gutter left of a line number to set a breakpoint. Press F5 to start debugging. Step through code with F10 (next line), F11 (step into), Shift+F11 (step out). Hover over variables to inspect values.
