如何调试和构建生产NodeJS [英] How to debug "built" production NodeJS

查看:79
本文介绍了如何调试和构建生产NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio代码在生产环境中调试节点应用程序

I am using Visual Studio code to debug a node application in production environment

Node进程在docker内部运行

The Node process runs inside docker,

我端口转发并发信号通知USR1以启用将VS代码中的调试器附加到该节点进程

I port-forwarded and signaled USR1 to enable attaching debugger from VS code to that node process

我的VS Code配置是这样的

My VS Code configuration is like this

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Debug: service",
      "sourceMaps": true,
      "smartStep": true,
      "remoteRoot": "/src/",
      "localRoot": "/home/my-username/work/orders/src/",
      "protocol": "inspector",
      "port": 9229,
      "restart": true,
      "address": "0.0.0.0",
      "skipFiles": [
        "<node_internals>/**",
        "<node_modules>/**"
      ]
    }
  ]
}

从VS代码中,我可以挂接到应用程序中,并且应用程序可能会因异常而中断但是,没有源映射会导致我的源代码中的所有断点都是未绑定断点"

From VS code, I can hook into the application and the application can break on exception However there is no source-mapping which cause all my breakpoint in my source-code to be "unbound breakpoint"

VS代码中已加载的脚本列表显示

The loaded script list in VS code show that

VS代码调试器能够在dist中查看我的源代码的node_modules和 build 版本.另一个值得注意的一点是,用于构建/dist的源代码也可以直接在生产服务器的上层文件夹中找到.

The VS code debugger is able to see the node_modules and the built version of my source code inside dist. One other notable point is that the source code that is used to build the /dist is also available directly in the production server, in the upper folder.

在这种情况下,如何使用未构建的源代码调试已构建的生产过程?

How can I debug the built production process, using my unbuilt source code in this case?

我将Chrome行为添加为单独的问题

I added Chrome behaviour as separate question

NodeJ:Chrome检查员可以映射源,但无法在原始源上进行调试

推荐答案

我不知道它是否对您有帮助.但是我认为您必须使用 node-inspector .可以从任何支持WebSocket的浏览器中使用它.真的很好.

I don't know whether it will be helpful to you or not. But I think you have to use node-inspector. It can be used from any browser supporting WebSocket. It is really good.

很酷的东西

  • Node Inspector使用WebSockets,因此不会轮询中断.
  • 远程调试和调试远程计算机.
  • 实时编辑正在运行的代码,可以选择将更改持久化回文件系统.
  • 在尚未加载到V8中的文件中设置断点-对于调试模块加载/初始化很有用.
  • 可嵌入到其他应用程序中-有关更多详细信息,请参见嵌入HOWTO".

这篇关于如何调试和构建生产NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆