使用node-inspector调试node.js [英] debugging node.js with node-inspector
问题描述
我正在尝试使用node-inspector调试我的nodejs应用程序.但是Google Chrome不会显示该代码.
I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.
我正在使用以下内容
Node.js:v0.10.26
Node.js : v0.10.26
快递:4.0.0
节点检查器:v0.7.3
Node Inspector : v0.7.3
Google Chrome版本:34.0.1847.131
Google Chrome version : 34.0.1847.131
这就是我启动调试器的过程.
This is what I'm doing to start the debugger..
$ node-inspector
Node Inspector v0.7.3
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
在另一个控制台中,
$ node --debug app.js
debugger listening on port 5858
$
然后启动Google Chrome浏览器并转到
Then started Google Chrome and went to
http://127.0.0.1:8080/debug?port=5858
它打开了节点检查器,但是没有任何代码..所有窗口都是空的.
It opens up node-inspector but without any code..all windows are empty.
注意到我没有收到"Express服务器在端口3000上监听"
Noticed that I'm not getting 'Express server listening on port 3000'
根据 node-inspector无法连接到节点但没有运气
无法解决我所缺少的内容.希望您有什么建议..所以我可以在Google Chrome中调试Node.js应用.
Couldn't work out what I'm missing. Would be great of you have any suggestions..so I can debug my Node.js apps in Google Chrome.
推荐答案
尝试运行node --debug-brk app.js
而不只是--debug
.在节点检查器挂接到节点进程之前,您的应用程序可能不会暂停.使用--debug-brk
将迫使节点在应用程序的第一行中断,并等待调试器附加到该进程.加载节点检查器Web界面是导致节点检查器附加到您的节点进程的原因.这就是为什么在查询字符串(localhost:8080/debug?port = 5858)中包含节点调试端口的原因.您是在告诉节点检查器它应该伸出并连接到哪个端口.
Try to run node --debug-brk app.js
instead of just --debug
. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brk
will force node to break on the first line of your app and wait for a debugger to attach to the process. Loading the node-inspector web interface is what causes node-inspector to attach to your node process; that's why you include the node debug port in the query string (localhost:8080/debug?port=5858). You're telling node-inspector what port it should reach out and attach to.
这是我放在一起的动画gif,展示了Node-inspector的完整安装和运行.
Here's an animated gif I put together showing a complete install and run of node-inspector.
在gif中,我使用--debug
标志,因为我没有调试任何在启动时就可以运行的代码.我在请求处理程序内调试,该处理程序仅在请求页面时才触发.因此,刷新页面会导致节点检查器在该行中断.
In the gif I use the --debug
flag because I'm not debugging any code that runs right at startup. I'm debugging inside a request handler, which only fires when the page is requested. Thus, refreshing the page causes node-inspector to break on that line.
不久前,我还整理了15分钟的YouTube教程.
I also put together a 15 minute YouTube tutorial a while ago.
希望对您有帮助!
这篇关于使用node-inspector调试node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!