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?
How can I debug a Node.js application running with PM2 in VSCode?
Asked Answered
how do you start a node.js application in debug mode that can be used by vscode? node --debug app.js? –
Mesozoic
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.
© 2022 - 2024 — McMap. All rights reserved.