How can I debug a Node.js application running with PM2 in VSCode?
Asked Answered
H

1

10

Visual Studio code has some awesome debug functionality built in that makes it easy to debug applications with node. However, my application is configured to use PM2. How can I set up Visual Studio Code to debug with PM2?

Herrah answered 4/12, 2016 at 18:9 Comment(1)
how do you start a node.js application in debug mode that can be used by vscode? node --debug app.js?Mesozoic
N
9

You can add a launch configuration in VSCode, in the file named launch.json, that attaches to the process you want like this:

{

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

Press ctrl+shift+D to show the debug section in Visual Studio Code, pick "Attach to Process" and then press "play". VSCode will automatically show you the options available on you local machine. Besides the process ids of the running node processes VSCode shows the full path of your node app so it is easy to pick the right process to attach.

Notice answered 14/6, 2017 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.