1

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

1 Answer 1

1

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:

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, that helped a lot. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.