earizon
earizon

Reputation: 2238

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.

Upvotes: 13

Views: 4701

Answers (3)

ForgetfulFellow
ForgetfulFellow

Reputation: 2632

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

Upvotes: 6

darky
darky

Reputation: 172

In node 8 version appeared async_hooks

trace uses this for async stack traces

Upvotes: 7

Peter Gelderbloem
Peter Gelderbloem

Reputation: 512

You can take a look at long stacktraces to see if it fits your needs. The module is called stackups. All you do is install it:

npm install --save stackup

and then require it:

require('stackup');

More info here: https://github.com/groundwater/node-stackup

Upvotes: 1

Related Questions