在Node.js中调试时如何查看变量?

在Node.js中调试时如何查看变量?,node.js,debugging,Node.js,Debugging,Node.js调试器隐藏了我的大多数字符串变量,它会打印…,就像这样:(有一个名为source的变量) (在repl内部时,变量会被截断,如上面最上面的代码段所示。) 和print(source)或print('source'): 可供选择的命令不多:(在调试器中) watch(“您的变量名”)将打印您在每个断点处观察的变量值(您必须将变量/表达式名放在引号中) 这似乎是命令行上最接近的东西,尽管坦率地说,这只是编写 console.log(我想记录的东西); 调试器 感觉更轻松。您是否尝试过在

Node.js调试器隐藏了我的大多数字符串变量,它会打印
,就像这样:(有一个名为
source
的变量)

(在repl内部时,变量会被截断,如上面最上面的代码段所示。)

print(source)
print('source')

可供选择的命令不多:(在调试器中)

watch(“您的变量名”)
将打印您在每个断点处观察的变量值(您必须将变量/表达式名放在引号中)

这似乎是命令行上最接近的东西,尽管坦率地说,这只是编写

console.log(我想记录的东西);
调试器


感觉更轻松。

您是否尝试过在调试命令行中不使用
console.log()
而直接键入变量名?如何使用
print
而不是
exec
?您好@Soviut,我只测试了键入
source
。然后调试器将找不到
源代码,因为
源代码
变量仅在Node.js debuggee进程中可用,而在调试器本身中不可用。您好@OmG,我测试了
打印
-没有这样的函数可用(不在调试器中,也不在repl中)。您不使用devtools有什么原因吗?
$ node debug 127.0.0.1:9101
debug> 
debug> exec('source')
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="DW dw-pri js no... (length: 6408)'
debug>
debug> repl
Press Ctrl + C to leave debug repl
> source
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="DW dw-pri js no... (length: 6408)'
debug> source
ReferenceError: source is not defined
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at Object.runInContext (vm.js:87:6)
    at Interface.controlEval (_debugger.js:971:21)
    at REPLServer.eval (_debugger.js:745:41)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)
debug> print('source')
ReferenceError: print is not defined
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at Object.runInContext (vm.js:87:6)
    at Interface.controlEval (_debugger.js:971:21)
    at REPLServer.eval (_debugger.js:745:41)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)
debug> repl
Press Ctrl + C to leave debug repl
> print(source)
ReferenceError: print is not defined
debug> help
Commands: run (r), cont (c), next (n), step (s),
out (o), backtrace (bt), setBreakpoint (sb), clearBreakpoint (cb),
watch, unwatch, watchers, repl, exec, restart, kill, list, scripts,
breakOnException, breakpoints, version