简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM