9

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 version 3.4.1. node version 6.17.1 How can I set up Visual Studio Code to debug with PM2?

ABDUL JAMAL
  • 452
  • 7
  • 12

2 Answers2

9

Vs code has a debugging option called “Attach” which allows you to attach to a running Node.js program, A sample configuration would be

{
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229
}

Now you need to start your Node.js program like below

$ pm2 start "My App" --node-args="--inspect-brk" --watch

vs code docs : https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations

Archit
  • 172
  • 10
  • I have .yaml file loaded by too many microservices. Then? Like apps: - name: account script: app.js out_file: /dev/null error_file: /dev/null cwd: ../sk_account env: UV_THREADPOOL_SIZE: 12 PUTTU_IP: 127.0.0.1 REDIS_CON: localhost:6379 ES_URL: localhost:9200 MONGO_URL: mongodb:// XAMPP_URL: HOST_NAME: localhost CONFIG_URL: ../config/globals.js - name: apigateway so on... – ABDUL JAMAL Jul 12 '19 at 10:33
  • can anyone reply on this! – ABDUL JAMAL Jul 15 '19 at 05:10
  • I'm not sure what you meant here, please check out this link for further details on how to attach process to vs code debugger. https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_attach-to-node-process-action – Archit Jul 16 '19 at 06:50
-3

Its possible to debug one of the micro-service from the list by stopping it like "sudo pm2 stop sk_account"

"version": "0.2.0",
"configurations": [
  {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/sk_account/app.js"
   }

]

Here "sk_account" is my micro-service name Form the list.

ABDUL JAMAL
  • 452
  • 7
  • 12