简体   繁体   English

调试在Docker上运行的整个Node.js代码

[英]Debug entire Node.js code running on Docker

I've setup Node.js with Docker and everything is working. 我已经用Docker设置了Node.js,并且一切正常。 I configured VS Code so I can do remote debugging and it's also working, but is there a way I can debug code that was executed before the debugger got attached? 我配置了VS Code,所以我可以进行远程调试,并且也可以运行,但是有没有办法调试在连接调试器之前执行的代码?

For example, in the image below, I can't debug line 3 and 9 because this code is executed when node is started and I can't attach a debugger without any node process running. 例如,在下图中,我无法调试第3行和第9行,因为此代码是在启动节点时执行的,并且在没有任何节点进程运行的情况下,我无法附加调试器。

在此处输入图片说明

Here's my Dockerfile's CMD: 这是我的Dockerfile的CMD:

nodemon --inspect=0.0.0.0:9229 src/index.js

You can start your instance and pause on first line with the flag --inspect-brk . 您可以启动实例并使用--inspect-brk标志在第一行暂停。 https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js

Or you can simply write a debugger statement on your code and it will pause once it reaches the statement line. 或者,您可以简单地在代码上编写debugger语句,一旦到达语句行,它将暂停。

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

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