package
[](https://travis-ci.org/stefanpenner/get-caller-file) [](https://ci.a
npm install get-caller-fileGitHub-flavored package documentation.
Across all versions, last 30 days.
810,493,481 in 30 days
Runtime metadata.
This is a utility, which allows a function to figure out from which file it was invoked. It does so by inspecting v8's stack trace at the time it is invoked.
Inspired by http://stackoverflow.com/questions/13227489
note: this relies on Node/V8 specific APIs, as such other runtimes may not work
yarn add get-caller-fileGiven:
// ./foo.js
const getCallerFile = require('get-caller-file');
module.exports = function() {
return getCallerFile(); // figures out who called it
};// index.js
const foo = require('./foo');
foo() // => /full/path/to/this/file/index.jsgetCallerFile(position = 2): where position is stack frame whos fileName we want.Estimated unpacked size across 1 packages.
4.6 kB
Includes dependencies.