V8 stacktrace API based caller's module information
npm install --save callers-module
var path = require('path');
var callersModule = require('callers-module');
// $ mocha test/fileName.js
module.exports = function(){
it('should give callers module', function(){
console.log(callersModule());
// => {
// module : 'mocha',
// scope : 'mocha/lib',
// path : 'node_modules/mocha/lib/runnable.js',
// location : 'node_modules/mocha/lib/runnable.js:249:21'
// };
})
}require('callers-module')([frames, origin])
framesif specified should be anintegerbigger than0orInfinity.originif specified should be a function.- if no arguments, the default number of
framesis2so theoriginis 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
npm test