简体   繁体   English

如何在VSCode中调试与PM2一起运行的Node.js应用程序?

[英]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. Visual Studio代码内置了一些非常棒的调试功能,可以轻松地使用节点调试应用程序。 However, my application is configured to use PM2. 但是,我的应用程序配置为使用PM​​2。 How can I set up Visual Studio Code to debug with PM2? 如何设置Visual Studio代码以使用PM2进行调试?

You can add a launch configuration in VSCode, in the file named launch.json , that attaches to the process you want like this: 您可以在名为launch.json的文件中的VSCode中添加启动配置,该配置将附加到您想要的进程,如下所示:

{

  "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 ". ctrl + shift + D在Visual Studio Code中显示调试部分,选择“ Attach to Process ”然后按“ play ”。 VSCode will automatically show you the options available on you local machine. VSCode将自动显示本地计算机上可用的选项。 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. 除了运行节点进程的进程ID之外,VSCode还显示了节点应用程序的完整路径,因此很容易选择正确的连接进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM