Inspect live objects/stack in node.js

887 views Asked by At

In node.js, is there something similar to inspect.stack() and inspect.currentFrame() from Python? Like, capturing code context/frames/inspecting live object.

1

There are 1 answers

1
rsp On BEST ANSWER

You can use new Error().stack to inspect the stack:

console.log(new Error().stack);

prints:

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)

There is node debugger that you can run with:

node debug script.js

See:

And you can also use Chrome developer tools for live inspection of everything with:

node --inspect script.js

See: