long stack traces for node.js
Last updated 7 years ago by shtylman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install superstack 
SYNC missed versions from official npm registry.

superstack Build Status

long stack traces for node.js over async/io boundaries


npm install superstack


Just require superstack in your project. Ideally one of the first requires (see how it works for why)

var superstack = require('superstack');

function f () {
    throw new Error('foo');
setTimeout(f, Math.random());
setTimeout(f, Math.random());

Your stack traces will now extend beyond async call boundaries. From the code above.

Before superstack

Error: foo
    at f [as _onTimeout] (.../node-superstack/foobar.js:2:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

We have no idea which setTimeout call actually caused the error.


Error: foo
    at f (/Users/shtylman/projects/node-superstack/foobar.js:4:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
    at Object.<anonymous> (/Users/shtylman/projects/node-superstack/foobar.js:7:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Notice that the stacktrace identifies which of the two setTimeout fired first and this caused the error.



By default, the stacktrace appears as one long stacktrace. If you want to see the superstack framing boundaries set this value to a string and it will appear in the callstack.


Set this to a positive number to limit the number of frames superstack will capture. This is how many nested async calls back to report. A values of -1 means unlimited. Default is 10.


Function used by superstack to format the stacktrace string. See the implementation for default. The default conforms to the v8 stacktrace strings.

how it works

Superstack works by intercepting certain node.js EventEmitter, process, and Timer APIs. By intercepting the api call and injecting a wrapper callback, any error can be captured and additional frame information added via Error.prepareStackTrace

The following calls are intercepted.


  • on/addListener
  • once
  • removeListener
  • listeners


  • nextTick
  • _nextDomainTick


  • setTimeout
  • setInterval
  • setImmediate


If you find an instance of usage that is not properly captured, please open an issue and provide a testcase to reproduce.

The usual npm test can be run. A more rigorous set of tests can be run by running the script in test/modules. It will clone a few popular node.js repos and run their test suits with superstack enabled. This helps ensure that there are limited side effects.


Thanks to mattinsler/longjohn and tlrobinson/long-stack-traces for the ideas and code. Longjohn code is MIT licensed.

Also relevant a pdf on the initial idea of long stack traces via an EventSource.



Current Tags

  • 0.0.4                                ...           latest (7 years ago)

4 Versions

  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Today 1
This Week 1
This Month 27
Last Day 0
Last Week 5
Last Month 20
Dependencies (0)
Dev Dependencies (2)

Copyright 2014 - 2017 © |