npm install callers-pathV8 stacktrace API based caller's path
npm install --save callers-path
example/moduleB.js
``js`
var callersPath = require('callers-path');
module.exports = function(){
console.log(callersPath());
};
example/moduleA.js
`js`
var moduleB = require('./moduleB');
moduleB();
// => example/moduleA.js
require('callers-path')([frames, origin])
- frames if specified should be an integer bigger than 0 or Infinity.origin
- if specified should be a function.frames
- if no arguments, the default number of is 2 so the origin is the module itself. The stack is sliced by one.
You would like to set how many frames are recorded (Error.stackTraceLimit) and from which function the stack should be traced back (Error.captureStackTrace).
By default two frames are recorded, though you can even lower it to one providing a function from which start.
It serves for the same use cases implemented on this cool modules
- visionmedia callsite
- sindresorhus callsites
- sindresorhus caller-path`
npm test