使用 node-inspector 调试 node.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23340968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
debugging node.js with node-inspector
提问by genwip
I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.
我正在尝试使用 node-inspector 调试我的 nodejs 应用程序。但谷歌浏览器不显示代码。
I'm using the following,
我正在使用以下内容,
Node.js : v0.10.26
Node.js:v0.10.26
Express : 4.0.0
快递:4.0.0
Node Inspector : v0.7.3
节点检查器:v0.7.3
Google Chrome version : 34.0.1847.131
谷歌浏览器版本: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.
In another console,
在另一个控制台中,
$ node --debug app.js
debugger listening on port 5858
$
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.
它打开节点检查器但没有任何代码..所有窗口都是空的。
Noticed that I'm not getting 'Express server listening on port 3000'
注意到我没有收到“Express 服务器在端口 3000 上侦听”
Tried all as per node-inspector fails to connect to nodebut no luck
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.
无法弄清楚我缺少什么。如果您有任何建议,那就太好了。所以我可以在 Google Chrome 中调试我的 Node.js 应用程序。
回答by Chev
Try to run node --debug-brk app.jsinstead of just --debug. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brkwill 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.
尝试运行node --debug-brk app.js而不仅仅是--debug. 在节点检查器挂钩到节点进程之前,您的应用程序可能不会暂停。使用--debug-brk将强制节点在应用程序的第一行中断并等待调试器附加到进程。加载节点检查器 Web 界面是导致节点检查器附加到您的节点进程的原因;这就是为什么在查询字符串中包含节点调试端口的原因 (localhost:8080/debug?port=5858)。您正在告诉节点检查器它应该伸出并附加到哪个端口。
Here's an animated gif I put together showing a complete install and run of node-inspector.
这是我放在一起的动画 gif,显示了 node-inspector 的完整安装和运行。
In the gif I use the --debugflag 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.
在 gif 中,我使用了--debug标志,因为我没有调试任何在启动时运行的代码。我正在一个请求处理程序中进行调试,该处理程序仅在请求页面时触发。因此,刷新页面会导致节点检查器在该行中断。
I also put together a 15 minute YouTube tutorial a while ago.
不久前,我还整理了一个 15 分钟的 YouTube 教程。
I hope that helps!
我希望这有帮助!
回答by Jerome Anthony
node-inspector by default tries to pre-load all the code before initiating the debug window. I have had instances, node-inspector just hangs for ever because of this pre-loading. Luckily the newer versions have an option to stop the pre-load thereby making the inspector load faster.
默认情况下,节点检查器会在启动调试窗口之前尝试预加载所有代码。我有过实例,由于这种预加载,节点检查器会永远挂起。幸运的是,较新的版本可以选择停止预加载,从而使检查器加载速度更快。
Try node-inspector --no-preload
尝试 node-inspector --no-preload
回答by elmpp
Standard remote debugging is broken entirely in node 6.5. It's replaced however by a new internal node feature
标准远程调试在节点 6.5 中完全中断。然而,它被一个新的内部节点功能所取代
$ node --inspect --debug-brk build/server/server.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/@62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
Debugger attached.
See here - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf- for more info
请参阅此处 - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf- 了解更多信息
回答by vinay gosain
--debug-brkis now deprecated
--debug-brk现在已弃用
try node --inspect-brk <your starting file name>and then go to chrome and type url
chrome://inspectand click on Open dedicated DevTools for Node,
the debugger will start, no need of node-inspector
尝试node --inspect-brk <your starting file name>然后转到 chrome 并输入 url
chrome://inspect并单击Open dedicated DevTools for Node,调试器将启动,不需要节点检查器
回答by clay


On the left of Node Inspector, "Sources" tab, there is "a box with a triangle in it" - highlighting says "Show Navigator". (See it in the picture above). Open that to find the files you want to debug, and put a break point on code that has yet to run.
在 Node Inspector 左侧的“Sources”选项卡上,有“一个带有三角形的框”——突出显示的是“Show Navigator”。(见上图)。打开它以找到要调试的文件,并在尚未运行的代码上放置一个断点。
Also note, if you want to debug code that runs on starting node, you'll need to use the --debug-brkoption when starting. Then, in Node Inspector, you you'll have to kick off the app (F8to run all). You'll need this option if you want to debug all the initialization code, like starting a web browser.
另请注意,如果要调试在起始节点上运行的代码,则需要--debug-brk在启动时使用该选项。然后,在 Node Inspector 中,您必须启动应用程序(F8以运行所有应用程序)。如果要调试所有初始化代码(例如启动 Web 浏览器),则需要此选项。
回答by Nevin Madhukar K
node-debug --no-preload app.js
node-debug --no-preload app.js
This what's working for me. Accoriding to this:
这对我有用。Accoriding来此:
My script runs too fast to attach the debugger.
The debugged process must be started with --debug-brk, this way the script is paused on the first line.
Note: node-debug adds this option for you by default.
我的脚本运行速度太快,无法附加调试器。
调试过程必须以 --debug-brk 启动,这样脚本会在第一行暂停。
注意:node-debug 默认为你添加了这个选项。

