1. caller
@substack's caller.js as a module
caller
Package: caller
Created by: totherik
Last modified: Mon, 10 Jul 2023 23:19:17 GMT
Version: 1.1.0
License: MIT
Downloads: 743,578
Repository: https://github.com/totherik/caller

Install

npm install caller
yarn add caller

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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code