【问题标题】:Remote debugging in Visual Studio CodeVisual Studio Code 中的远程调试
【发布时间】:2018-11-04 17:22:44
【问题描述】:

我在 AWS EC2 实例中托管了一个 node.js 应用程序。我使用 .pem 文件 ssh 进入主机进行身份验证。有什么方法可以在 VS Code 中调试此代码,我看到 VS Code 中有remote debugging,有指定端口和主机的配置,但没有指定 pem 文件的选项。

我应该如何配置 VS 代码进行调试?

【问题讨论】:

    标签: node.js amazon-web-services amazon-ec2 visual-studio-code remote-debugging


    【解决方案1】:

    我也面临同样的问题,解决方案非常简单,将检查器绑定到 0.0.0.0 而不是 127.0.0.1

    所以把你的 package.json 脚本改成这样:

    scripts:{
     "debug": node --inspect=0.0.0.0:9229 ./bin/www
     ...
    }
    

    参考:https://medium.com/@auchenberg/introducing-remote-debugging-of-node-js-apps-on-azure-app-service-from-vs-code-in-public-preview-9b8d83a6e1f0

    【讨论】:

      【解决方案2】:

      根据remote debugging Node 上的 VS Code 文档,您需要为 EC2 实例指定 TCP/IP 地址和端口号。这些是在您工作区的.vscode 文件夹中的launch.json 文件的address 属性中设置的。

      这是一个例子:

      {
          "type": "node",
          "request": "attach",
          "name": "Attach to remote",
          "address": "TCP/IP address of process to be debugged",
          "port": "9229"
      }
      

      确保端口(本例中为 9229)包含在安全组的规则中,以允许此端口的流量。如果您需要查看此内容,这里是overview of rules and security groups for Linux instances

      【讨论】:

      • 那是为了在 ec2-instance 上调试 node.js。 OP 正在询问如何编辑托管在 EC2 实例上的代码。我实际上正在尝试自己解决这个问题。
      • 我不同意,问题标题,第一段和最后一句询问调试,而不是编辑。
      猜你喜欢
      • 2021-10-23
      • 2019-04-02
      • 2017-07-11
      • 1970-01-01
      • 2013-08-01
      • 2018-03-22
      • 2014-05-09
      • 2023-03-29
      • 2018-07-26
      相关资源
      最近更新 更多