53

我正在尝试使用节点调试器。我正在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

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

额外的问题:是否有任何方法可以使用 Chrome 的开发人员工具 (CTRL-J),以便它连接到节点并以这种方式工作?(我知道节点检查器,但它非常过时并且......)

4

2 回答 2

85

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

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

于 2012-12-18T05:22:46.157 回答
4

The answer to the bonus question has changed in 2018.

Run node inspect foo.js.

Visit chrome://inspect and in the list of devices you should see an entry that says Target (<process.version>) with an accompanying inspect link.

It looks like this: enter image description here

于 2018-12-07T02:57:11.753 回答