I'm currently trying to debug my NodeJS app through visual studio code. When I run the program through PowerShell I run it using "npm start". When trying to debug the app in Visual Studio Code, I get errors inside of NodeJS internal files. This is what my configuration file looks like (it's the default one provided):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\server.js"
}
]
}
Trying to change "program" to "npm start" doesn't work.
Open up Preferences > Settings and in the search box type in “node debug”. Under the Extensions tab there should be one extension titled “Node debug”. From here, click the first box: Debug > Node: Auto Attach and set the drop down to “on”. You're almost ready to go now.
You can run npm scripts with a launch configuration, but your npm script needs to start node in debug mode. Example:
In package.json:
"scripts": {
"start": "node --nolazy --inspect-brk=9229 server.js
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"runtimeExecutable": "npm",
"runtimeArgs": [ "start" ],
"port": 9229
}
]
}
or, change your launch config to do exactly whatver npm start
is doing.
Docs for using 'npm' in launch config: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With