简体   繁体   English

使用node-inspector的调试脚本不起作用

[英]Debugging script using node-inspector is not working

I am trying to debug a very simple script using "node-inspector". 我正在尝试使用“ node-inspector”调试一个非常简单的脚本。 I tried both following instructions on the repo , which include running "node-debug" and instructions here which include running "node --debug-brk yourApp.js". 我尝试了以下关于回购的说明 ,其中包括运行“ node-debug”和此处的说明其中包括运行“ node --debug-brk yourApp.js”。

The main problem is that neither of the commands "node", "node-debug" or "node-inspector" return any result. 主要问题是命令“ node”,“ node-debug”或“ node-inspector”均未返回任何结果。 They just return silently. 他们只是默默地返回。

Running "nodejs --debug-brk myScript.js" on the other hand works, but does not seem to have a nice debug GUI. 另一方面,运行“ nodejs --debug-brk myScript.js”是可行的,但似乎没有一个好的调试GUI。 I can connect to it on http://127.0.0.1:5858/ but it is hardly useful for variable inspection. 我可以在http://127.0.0.1:5858/上连接到它,但是它对于变量检查几乎没有用。

Once you've installed node-inspector globally (with npm install -g node-inspector ) you can use it to connect to a nodejs process that's been run in debug mode. 全局安装了node-inspector (使用npm install -g node-inspector ),您可以使用它连接到已在调试模式下运行的nodejs进程。 Try the following steps. 请尝试以下步骤。

  1. Open two terminal windows 打开两个终端窗口
  2. In the first, run your process you'd like to debug with node --debug-brk myscript.js 首先,运行您要使用node --debug-brk myscript.js进行调试的过程
  3. In the second, run node inspector with node-inspector 在第二个中,使用node-inspector运行节点node-inspector
  4. In Chrome, visit the following address: http://localhost:8080/debug?port=5858 在Chrome中,访问以下地址: http://localhost:8080/debug?port=5858

What you've done here is start node in debug mode (at port 5858 by default), then launch node inspector, which runs its own webserver on port 8080. The URL (the debug?port=5858 part) is telling node-inspector to connect to the node debug process that's on port 5858. Once you're in there, you'll see that your process has stopped on the first line (as instructed to by --debug-brk ). 您在此处执行的操作是在调试模式下启动节点(默认为端口5858),然后启动节点检查器,后者在端口8080上运行自己的Web服务器。URL( debug?port=5858部分)告诉node-inspector连接到端口5858上的节点调试进程。进入该端口后,您会看到进程已在第一行停止(如--debug-brk所指示)。 You can then set any other breakpoints you'd like, then press the "play" button to start your process running! 然后,您可以设置任何其他断点,然后按“播放”按钮开始运行您的进程!

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

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