# caller-callsite

> Get the callsite of the caller function

Latest version **6.0.0** (published 2025-09-21) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2025-09-21 |
| First published | 2015-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 53 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | caller, calling, module, parent, callsites, callsite, stacktrace, stack, trace, function, file |

## Links

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

## Dependencies (1)

- [callsites](https://npm.io/package/callsites.md) ^4.2.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 6.0.0 (latest) — 2025-09-21
- 5.0.0 — 2021-10-07
- 4.1.0 — 2019-07-09
- 4.0.0 — 2019-05-03
- 3.0.0 — 2018-05-25
- 2.0.0 — 2016-08-28
- 1.0.1 — 2016-08-28
- 1.0.0 — 2015-01-24

## README

# caller-callsite

> Get the [callsite](https://github.com/sindresorhus/callsites#api) of the caller function

## Install

```sh
npm install caller-callsite
```

## Usage

```js
// foo.js
import callerCallsite from 'caller-callsite';

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

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

## API

### callerCallsite(options?)

Returns a [`callsite`](https://github.com/sindresorhus/callsites#api) object.

#### options

Type: `object`

##### depth

Type: `number`\
Default: `0`

The callsite depth, meaning how many levels we follow back on the stack trace from the caller.

For example:

```js
// foo.js
import callerCallsite from 'caller-callsite';

export default function foo() {
	console.log(callerCallsite().getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/bar.js'
	console.log(callerCallsite({depth: 1}).getFileName());
	//=> '/Users/sindresorhus/dev/unicorn/foobar.js'
}
```

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

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

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

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