【发布时间】:2017-05-07 20:46:46
【问题描述】:
在 node.js 中,有没有类似于 Python 中的 inspect.stack() 和 inspect.currentFrame() 的东西?
比如,捕获代码上下文/帧/检查活动对象。
【问题讨论】:
标签: javascript node.js callstack
在 node.js 中,有没有类似于 Python 中的 inspect.stack() 和 inspect.currentFrame() 的东西?
比如,捕获代码上下文/帧/检查活动对象。
【问题讨论】:
标签: javascript node.js callstack
您可以使用new Error().stack 来检查堆栈:
console.log(new Error().stack);
打印:
Error
at repl:1:13
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:313:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:513:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
有可以运行的节点调试器:
node debug script.js
见:
您还可以使用 Chrome 开发人员工具对所有内容进行实时检查:
node --inspect script.js
见:
【讨论】: