node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »



Stack traces in JSON format.


npm install stack-json


console.log(new Error().stackJSON);
// All error objects contain the stackJSON property. 

The property is lazy-loaded and as such does not harm the performance of your production code. However generating the JSON stack trace can take a while (not very long, but it is looking up files synchronously, if not already cached).

Since the module use stack-chain to do the stack trace magic, you can use it together with other modules that provides stack trace features. For example you can use it with trace, which gives you a nice long stack trace in asynchronous code (mainly when debugging):

require('trace'); // load it after this module 
setTimeout(function() {
  try {
  } catch (error) {
}, 100);

You can create your own formatted stack traces. This is the technique that stack-formatted use. Here is a short example:

function format(stack) {
  return {
    return '  ' + +
      '  ' + frame.filename + ':' + frame.line +
      '  ' + (frame.functionName || '(anon)');
console.log(format(new Error().stackJSON));

The package information in each stack frame (the pkg property) is gathered using the package-lookup module.