【问题标题】:Inspecting variables using node's built-in debugger?使用节点的内置调试器检查变量?
【发布时间】:2018-12-07 10:57:11
【问题描述】:

我正在尝试使用节点调试器。 我正在运行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),以便它连接到节点并以这种方式工作? (我知道节点检查器,但它非常过时并且......)

【问题讨论】:

    标签: node.js debugging


    【解决方案1】:

    使用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

    【讨论】:

    • 奖金问题呢? :D
    • 不确定是否有除节点检查器之外的现成解决方案,但您可以尝试使用 chrome 开发人员工具远程调试器 - developers.google.com/chrome-developer-tools/docs/…
    • 知道如何让它输出完整的变量而不是截断它吗?
    • 那是一个字符串吗? V8 调试器代理只返回字符串的前 80 个字符,因此您必须选择其他部分(mystring.slice(123) - 从索引 123 开始的子字符串)或要求被调试者输出它(console.log(mystring)
    【解决方案2】:

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

    运行node inspect foo.js

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

    看起来像这样:

    【讨论】:

    • 问题的答案是什么?你如何检查变量?
    猜你喜欢
    • 2014-04-04
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 2016-08-23
    • 2014-09-28
    • 1970-01-01
    • 2015-07-16
    相关资源
    最近更新 更多