使用节点的内置调试器检查变量?

时间:2012-12-18 04:13:47

标签: node.js debugging

我正在尝试使用节点调试器。 我正在运行node debug server来运行我的服务器。然后我有:

...
var Workspace = mongoose.model('Workspace');
debugger;

此时,正如预期的那样,当我运行此代码时,弹出调试器。 但是,我希望它能够设置所有当前变量,就像在Chrome自己的调试器中一样。

可是:

break in hotplate/node_modules/bd/lib/bd.js:133
132 
133   debugger;
134 
135   // Delete the ID and the version since there's no point,
debug> Workspace
ReferenceError: Workspace is not defined

那么......我如何实际检查当前变量?

Bonus问题:有没有办法使用Chrome的开发人员工具(CTRL-J),以便它连接到节点并以这种方式工作? (我知道node-inspector,但它已经过时了......)

2 个答案:

答案 0 :(得分:77)

使用repl命令(参见docs中的第三个示例)

break in hotplate/node_modules/bd/lib/bd.js:133
132 
133   debugger;
134 
135   // Delete the ID and the version since there's no point,
debug> repl
Press Ctrl + C to leave debug repl
> Workspace

更新:红利问题 - https://github.com/c4milo/node-webkit-agent

答案 1 :(得分:3)

奖金问题的答案在2018年发生了变化。

运行node inspect foo.js

访问chrome://inspect,并在设备列表中,您应该看到一个带有Target (<process.version>)的条目以及相应的检查链接。

它看起来像这样: enter image description here

相关问题