Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 600
ABDUL JAMAL Avatar asked Jul 12 '19 07:07

ABDUL JAMAL


People also ask

How do I enable debugging in VS Code?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.

Does VS Code have a debugger?

Debugging is a core feature of Visual Studio Code. In this tutorial, we will show you how to run and debug a program in VS Code. We'll take a tour of the Run and Debug view, explore some debugging features, and end by setting a breakpoint.

How do I Debug node in Visual Studio?

The easiest way to start a debugging session in Visual Studio Code is to open a file in the editor, click the Run View icon in the Activity Bar (or press Ctrl+Shift+D on your keyboard), followed by the Run and Debug button at the top left corner of the application.


1 Answers

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

like image 193
Archit Avatar answered Oct 18 '22 04:10

Archit