zoukankan      html  css  js  c++  java
  • 如何用Visual Studio Code远程调试运行在服务器上的nodejs应用

    假设我有一个nodejs应用,运行在AWS - 亚马逊云平台上(Amazone Web Service)。我想用本地的Visual Studio Code来远程调试服务器端的nodejs应用。

    Visual Studio Code的调试配置里定义了两种类型,attach和launch。Visual Studio Code的官方文档对这两种调试启动行为的解释:

    The best way to explain the difference between launch and attach is think of a launch configuration as a recipe for how to start your app in debug mode before VS Code attaches to it,

    Launch的意思简而言之就是以debug模式启动app。

    while an attachconfiguration is a recipe for how to connect VS Code's debugger to an app or process that's alreadyrunning.

    而Attach的含义是将Visual Studio Code的调试器绑定到一个已经处于运行状态的应用。

    因为我的需求是用本地的Visual Studio Code去调试AWS上正在运行的nodejs应用,毫无疑问应该选Attach。
    点击debug configuration这个按钮:

    自动弹出存放调试配置信息的launch.json文件了:

    把launch.json的内容替换成下面的内容:

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            
            {
                "type": "node",
                "request": "attach",
                "name": "Jerry's first debug config",
                "address": "127.0.0.1",
                "port": 9221
            }
        ]
    }
    

    这个配置文件的含义是告诉Visual Studio Code的调试进程,去连接127.0.0.1:9221上的应用调试进程去调试。

    当然,最后一步我们还需要将本地的127.0.0.1:9221同AWS上的调试进程使用ssh做一个绑定。

    ssh -i C:Usersi042416.sshKOI.pem -L 9221:localhost:9229 ubuntu@amazonaws.com

    一切就绪后,做一个操作触发AWS上nodejs应用的执行。比如我在AWS上部署了一个nodejs应用,作为我github repository的webhook。每当我在这个仓库创建issue时,github网站就会推送一个事件到我的webhook上去。

    现在我创建了一个名为test create issue的issue,一旦我点了Close按钮,

    这个issue close事件会自动发送到我的AWS应用,下图可以看到断点触发了,这样我就实现了使用本地的Visual Studio Code远程调试AWS应用的目的。

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    杜教筛
    linux运维好书推荐:《高性能Linux服务器构建实战Ⅱ》热销中,附实例源码下载
    分布式监控系统ganglia配置文档
    基于Web应用的性能分析及优化案例
    一次Linux系统被攻击的分析过程
    Keepalived中Master和Backup角色选举策略
    linux运维好书《高性能Linux服务器构建实战Ⅱ》已出版发售,附封面照!
    并行分布式运维工具pdsh
    安全运维之:Linux系统账户和登录安全
    安全运维之:文件系统安全
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/10841461.html
Copyright © 2011-2022 走看看