Search code examples
node.jsdebuggingtrace

NodeJS: Is is possible to show the stack trace of a calling async function?


Most APIs in node libraries are asynchronous by design. When an exception is thrown in a callback the stacktrace shows only the call stack starting at process._tickCallback.

I wonder whether there is a trick to show also the stack trace of the function that trigerred the _tickCallback.


Solution

  • In Node.js 12, Async Stack Traces come out of the box with flag

    --async-stack-traces
    

    Node.js Foundation release post - https://medium.com/@nodejs/introducing-node-js-12-76c41a1b3f3f