# locate-path

> Get the first path that exists on disk of multiple paths

Latest version **8.0.0** (published 2025-09-15) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2025-09-15 |
| First published | 2016-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 64 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | locate, path, paths, file, files, exists, find, finder, search, searcher, array, iterable, iterator |

## Links

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

## Dependencies (1)

- [p-locate](https://npm.io/package/p-locate.md) ^6.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

- 8.0.0 (latest) — 2025-09-15
- 7.2.0 — 2023-02-09
- 7.1.1 — 2022-06-06
- 7.1.0 — 2022-02-08
- 7.0.0 — 2021-08-25
- 6.0.0 — 2020-08-10
- 5.0.0 — 2019-05-04
- 4.0.0 — 2019-04-15
- 3.0.0 — 2018-06-17
- 2.0.0 — 2016-11-28
- 1.1.0 — 2016-11-20
- 1.0.0 — 2016-11-20

## README

# locate-path

> Get the first path that exists on disk of multiple paths

## Install

```sh
npm install locate-path
```

## Usage

Here we find the first file that exists on disk, in array order.

```js
import {locatePath} from 'locate-path';

const files = [
	'unicorn.png',
	'rainbow.png', // Only this one actually exists on disk
	'pony.png'
];

console.log(await locatePath(files));
//=> 'rainbow.png'
```

## API

### locatePath(paths, options?)

Returns a `Promise<string>` for the first path that exists or `undefined` if none exists.

#### paths

Type: `Iterable<string>`

The paths to check.

#### options

Type: `object`

##### concurrency

Type: `number`\
Default: `Infinity`\
Minimum: `1`

The number of concurrently pending promises.

##### preserveOrder

Type: `boolean`\
Default: `true`

Preserve `paths` order when searching.

Disable this to improve performance if you don't care about the order.

##### cwd

Type: `URL | string`\
Default: `process.cwd()`

The current working directory.

##### type

Type: `string`\
Default: `'file'`\
Values: `'file' | 'directory' | 'both'`

The type of path to match.

- `'file'` - Only match files
- `'directory'` - Only match directories
- `'both'` - Match both files and directories

##### allowSymlinks

Type: `boolean`\
Default: `true`

Allow symbolic links to match if they point to the chosen path type.

### locatePathSync(paths, options?)

Returns the first path that exists or `undefined` if none exists.

#### paths

Type: `Iterable<string>`

The paths to check.

#### options

Type: `object`

##### cwd

Same as above.

##### type

Same as above.

##### allowSymlinks

Same as above.

## Related

- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists

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