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

Mer*_*erc 48 debugging node.js

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

...
var Workspace = mongoose.model('Workspace');
debugger;
Run Code Online (Sandbox Code Playgroud)

此时,正如预期的那样,当我运行此代码时,调试器会弹出.但是,我希望它能够设置所有当前变量,就像在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
Run Code Online (Sandbox Code Playgroud)

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

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

And*_*rov 78

使用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
Run Code Online (Sandbox Code Playgroud)

更新:奖金问题 - https://github.com/c4milo/node-webkit-agent

  • 任何想法如何让它输出完整变量而不是截断它? (2认同)
  • 那是一个字符串?V8调试器代理只返回一个字符串的前80个字符,所以你必须选择其他部分(`mystring.slice(123)` - 从索引123开始的子字符串)或要求debuggee输出它(`console.log(mystring)` ) (2认同)

And*_*ell 5

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

跑步node inspect foo.js

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

它看起来像这样: 在此输入图像描述

  • 问题的答案是什么?你如何检查变量? (4认同)