# p-locate

> Get the first fulfilled promise that satisfies the provided testing function

Latest version **7.0.0** (published 2026-02-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-02-03 |
| First published | 2016-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 1 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 82 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, locate, find, finder, search, searcher, test, array, collection, iterable, iterator, race, fulfilled, fastest, async, await, promises, bluebird |

## Links

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

## Dependencies (1)

- [p-limit](https://npm.io/package/p-limit.md) ^7.2.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 7.0.0 (latest) — 2026-02-03
- 6.0.0 — 2021-08-25
- 5.0.0 — 2020-08-10
- 4.1.0 — 2019-04-04
- 4.0.0 — 2019-03-12
- 3.0.0 — 2018-06-15
- 2.0.0 — 2016-11-28
- 1.0.0 — 2016-11-20

## README

# p-locate

> Get the first fulfilled promise that satisfies the provided testing function

Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).

## Install

```sh
npm install p-locate
```

## Usage

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

```js
import {pathExists} from 'path-exists';
import pLocate from 'p-locate';

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

const foundPath = await pLocate(files, file => pathExists(file));

console.log(foundPath);
//=> 'rainbow.png'
```

*The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*

## API

### pLocate(input, tester, options?)

Returns a `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`.

#### input

Type: `Iterable<Promise | unknown> | AsyncIterable<unknown>`

An iterable or async iterable of promises/values to test.

When an `AsyncIterable` is given, it is iterated serially and the `concurrency` and `preserveOrder` options are not applicable.

#### tester(element)

Type: `Function`

This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.

#### options

Type: `object`

##### concurrency

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

The number of concurrently pending promises returned by `tester`.

##### preserveOrder

Type: `boolean`\
Default: `true`

Preserve `input` order when searching.

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

## Related

- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
- [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
- [More…](https://github.com/sindresorhus/promise-fun)

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