检查node.js中的活动对象/堆栈
在node.js中,是否有类似于Python的inspect.stack()
和inspect.currentFrame()
? 就像捕获代码上下文/框架/检查活动对象一样。
您可以使用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)
有可以运行的节点debugging器:
node debug script.js
看到:
而且您还可以使用Chrome开发人员工具对以下各项进行实时检查:
node --inspect script.js
看到:
- 在Chrome DevTools中通过Matt DesLauriersdebuggingNode.js
- 用Paul Irish的Chrome DevToolsdebuggingNode.js