caller
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/caller package

1.1.0 • 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`
};

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    325,513
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    325,513
  • 1.0.1
    215,529
  • 1.0.0
    14
  • 0.0.1
    342,270

Package Sidebar

Install

npm i caller

Weekly Downloads

164,511

Version

1.1.0

License

MIT

Unpacked Size

3.88 kB

Total Files

5

Last publish

Collaborators

  • totherik
  • krakenjs-user