caller-path
Get the path of the caller function
Important: You have to use 'use strict';
in your code for this module to work correctly, or make sure the module is an ESM module, which is implicitly strict.
Install
$ npm install caller-path
Usage
const callerPath = require('caller-path');
module.exports = () => {
console.log(callerPath());
}
const foo = require('./foo');
foo();
If the caller's callsite object getFileName
was not defined for some reason, it will return undefined
.
API
callerPath(options?)
Get the path of the caller function.
depth
Type: number
Default: 0
The caller path depth, meaning how many levels we follow back on the stack trace.
For example:
const callerPath = require('caller-path');
module.exports = () => {
console.log(callerPath());
console.log(callerPath({depth: 1}));
console.log(callerPath({depth: 2}));
}
const foo = require('./foo');
module.exports = () => {
foo();
}
const bar = require('./bar');
bar();