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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With