3
votes

I'm testing out the VS Code node debugger, but I'm not able to find any node processes when trying to attach to a running process.

This is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach by Process ID",
            "processId": "${command:PickProcess}"
        }
    ]
}

the contents of my package.json file:

  "scripts": {
    "start": "node --inspect=0.0.0.0:9229 ./bin/www"
  }

After I start up the process using 'npm start', I press 'start debug' and the list of node processes is:

  • 1 sssd_pam
  • 1 sssd_nss
  • 1 sssd_be

Looks like this and none of these are the server I just launched. This list persists even after I take down the node server.

Why am I not able to see any of my running node processes in the VSCode process attach?

P.s. I'm closely following this tutorial on debugging Node.js with VS Code.

1
Please, post the scripts in your package.json file so we can help. Maybe there's a problem with the NPM Start script. - Luís Brito
Edited the post to include that. - Michael
After adding --inspect=0.0.0.0:9229 to the npm script, it is now working. Thank you! - Michael
Glad I was able to help! - Luís Brito

1 Answers

3
votes

Are you running the NodeJS in debug mode inside npm start? You need to use the --inspect flag. Without this flag, the NodeJS interpreter won't open the debug port to the VSCode to attach to.

Refer to: https://nodejs.org/en/docs/guides/debugging-getting-started/

Another option is to attach using a port definition. I usually do something like this in the launch.json:

{
  "type": "node",
  "request": "attach",
  "name": "Attach",
  "port": 9229,
  "restart": true,
  "sourceMaps": true,
  "protocol": "inspector"
}

Then I start the NodeJS process as: node --inspect=0.0.0.0:9229 start.js