Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

caller

1.0.1 • Public • Published

caller

Figure out your caller (thanks to @substack).

Initialization Time Caller
// foo.js
 
var bar = require('bar');
// bar.js
 
var caller = require('caller');
console.log(caller()); // `/path/to/foo.js`
Runtime Caller
// foo.js
 
var bar = require('bar');
bar.doWork();
// bar.js
 
var caller = require('caller');
 
exports.doWork = function () {
    console.log(caller());  // `/path/to/foo.js`
};

Depth

Caller also accepts a depth argument for tracing back further (defaults to 1).

// foo.js
 
var bar = require('bar');
bar.doWork();
// bar.js
 
var baz = require('baz');
 
exports.doWork = function () {
    baz.doWork();
};
// baz.js
 
var caller = require('caller');
 
exports.doWork = function () {
    console.log(caller(2));  // `/path/to/foo.js`
};

install

npm i caller

Downloadsweekly downloads

96,735

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability