Socket
Socket
Sign inDemoInstall

caller-path

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    caller-path

Get the path of the caller function


Version published
Weekly downloads
6.2M
decreased by-9.27%
Maintainers
1
Install size
19.2 kB
Created
Weekly downloads
 

Package description

What is caller-path?

The caller-path npm package is designed to help developers retrieve the path of the file that calls a function. This can be particularly useful for debugging, logging, and tracking the flow of a program, especially in complex applications where functions are called from multiple places.

What are caller-path's main functionalities?

Get caller file path

This feature allows developers to log or retrieve the path of the file that called a function. In the provided code, the function `whoCalled` uses `callerPath()` to print the path of the caller file.

const callerPath = require('caller-path');

function whoCalled() {
  console.log(callerPath());
}

module.exports = whoCalled;

Other packages similar to caller-path

Readme

Source

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

// foo.js
const callerPath = require('caller-path');

module.exports = () => {
	console.log(callerPath());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
}
// bar.js
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:

// foo.js
const callerPath = require('caller-path');

module.exports = () => {
	console.log(callerPath());
	//=> '/Users/sindresorhus/dev/unicorn/foobar.js'
	console.log(callerPath({depth: 1}));
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
	console.log(callerPath({depth: 2}));
	//=> '/Users/sindresorhus/dev/unicorn/foo.js'
}
// bar.js
const foo = require('./foo');

module.exports = () => {
	foo();
}
// foobar.js
const bar = require('./bar');
bar();

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 18 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc