我想要什么
我希望能够在使用 node-inspector
和 Web Inspector 进行调试期间在 node
中运行整个脚本。 - 我不想想要逐步执行各个 JavaScript 调用。
我做了什么
(我的 PowerShell 说明)
PS C:\Users\JK> node-inspector
info - socket.io started
visit http://0.0.0.0:8080/debug?port=5858 to start debugging
...
==[In another PowerShell instance:]==
PS %> node —debug-brk myscript.js
debugger listening on port 5858
为什么我想要这个
我正在编写一个 Node 脚本。在此脚本中,我 console.log
许多对象,以便能够在调试过程中探索它们。但是简单的静态文本控制台输出并不是很好 - 您无法折叠和展开对象的属性或获取函数的源代码:
(例如)
{ [Function: Xy]
a: [Function],
b: 8.2,
c: [Function],
d: [Circular],
e: '2011-11-11' }
因此,我决定将 Web Inspector 与 node-inspector
一起使用,以获得良好的对象浏览体验(因为 Web Inspector 良好的输出格式)。
为什么我不单步执行
(我的脚本的结构)
var fs = require('fs');
fs.readFile('myfile', function (err, data) {
if (err) {
throw err;
}
//My Script...
console.log(something);
});
console.log()
调用在回调函数中执行require('fs').readFile()
。我不会仅仅以“正常”到达那里 步骤。- 一次又一次点击步骤按钮实在是太无聊了。
我的问题
- 是否可以使用以下 Web Inspector 用户界面来运行脚本而不单步执行? (我不想使用
node —debug myscript.js
而不是node —debug-brk myscript.js
因为 Inspector 会抛出Error: connect ECONNREFUSED Node 是否使用 --debug 端口 5858 运行?
因为脚本运行太快)
(Web 检查器界面)
- 或者至少有任何其他方式来完成我上面描述的操作(在为什么我想要这个部分)。
谢谢。 - (我希望我想问的问题很清楚。-如果不是,请写评论。)
最佳答案
您有几个选择。
使用--debug-brk
:
启动脚本,让它停在第一行。
在“脚本” Pane 中,单击回调内的行号(行 4 在这个 示例)。
点击“继续”(右侧面板上方的“|>”图标)。
使用--debug
:
- 将行
debugger;
添加到您的回调中。这将停止 那时的调试器。完成后点击“|>”。
关于debugging - Node 检查器 : Running Code - Not Just Stepping Through,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12446079/