Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 271
Chandler Freeman Avatar asked Dec 04 '16 18:12

Chandler Freeman


People also ask

How do I Debug a console application using Visual Studio Code?

Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.


1 Answers

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.

like image 140
Jos Avatar answered Sep 19 '22 17:09

Jos