# caller-path

> Get the path of the caller function

Latest version **4.0.0** (published 2021-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install caller-path
pnpm add caller-path
yarn add caller-path
bun add caller-path
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-10-08 |
| First published | 2014-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 67 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | caller, calling, module, path, parent, callsites, callsite, stacktrace, stack, trace, function, file |

## Links

- npm: https://www.npmjs.com/package/caller-path
- Repository: https://github.com/sindresorhus/caller-path
- Homepage: https://github.com/sindresorhus/caller-path#readme
- Issues: https://github.com/sindresorhus/caller-path/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/caller-path

## Dependencies (1)

- [caller-callsite](https://npm.io/package/caller-callsite.md) ^5.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-10-08
- 3.0.1 — 2021-04-18
- 3.0.0 — 2019-11-22
- 2.0.0 — 2016-08-28
- 1.0.0 — 2015-01-24
- 0.1.0 — 2014-04-19

## README

# caller-path

> Get the path of the caller function

## Install

```sh
npm install caller-path
```

## Usage

```js
// foo.js
import callerPath from 'caller-path';

export default function foo() {
	console.log(callerPath());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
}
```

```js
// bar.js
import foo from './foo.js';
foo();
```

If the caller's [callsite](https://github.com/sindresorhus/callsites#api) 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:

```js
// foo.js
import callerPath from 'caller-path';

export default function foo() {
	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'
}
```

```js
// bar.js
import foo from './foo.js';

export default function bar() {
	foo();
}
```

```js
// foobar.js
import bar from './bar.js';
bar();
```

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-caller-path?utm_source=npm-caller-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

---
_Source: https://npm.io/package/caller-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
