# wait-for-localhost

> Wait for localhost to be ready

Latest version **5.0.2** (published 2026-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install wait-for-localhost
pnpm add wait-for-localhost
yarn add wait-for-localhost
bun add wait-for-localhost
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.2 |
| Published | 2026-05-15 |
| First published | 2018-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | wait, localhost, server, port, delay, sleep, ready |

## Links

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

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 5.0.2 (latest) — 2026-05-15
- 5.0.1 — 2025-10-02
- 5.0.0 — 2025-09-10
- 4.1.0 — 2024-05-17
- 4.0.1 — 2022-08-08
- 4.0.0 — 2021-08-15
- 3.3.0 — 2020-07-24
- 3.2.0 — 2019-04-03
- 3.1.0 — 2019-02-27
- 3.0.1 — 2019-02-26
- 3.0.0 — 2019-01-14
- 2.0.1 — 2018-06-13
- 2.0.0 — 2018-06-08
- 1.0.0 — 2018-05-23

## README

# wait-for-localhost

> Wait for localhost to be ready

Useful if you need a local server to be ready to accept requests before doing other things.

Supports both HTTP/1 and HTTP/2 servers with automatic fallback.

## Install

```sh
npm install wait-for-localhost
```

## Usage

```js
import waitForLocalhost from 'wait-for-localhost';

await waitForLocalhost({port: 8080});
console.log('Server is ready');
```

## API

### waitForLocalhost(options?)

Returns a `Promise<object>` that settles when localhost is ready.

The object contains an `ipVersion` property with a value of either `6` or `4` depending on the IP version that was used.

#### options

Type: `object`

##### port

Type: `number`\
Default: `80`

##### path

Type: `string`\
Default: `'/'`

Use a custom path.

For example, `/health` for a health-check endpoint.

##### useGet

Type: `boolean`\
Default: `false`

Use the `GET` HTTP-method instead of `HEAD` to check if the server is running.

##### statusCodes

Type: `number[]`\
Default: `[200]`

HTTP status codes to consider as successful responses.

##### signal

Type: `AbortSignal`

An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to abort the operation.

```js
import waitForLocalhost from 'wait-for-localhost';

// Timeout after 5 seconds
await waitForLocalhost({
	port: 8080,
	signal: AbortSignal.timeout(5000)
});
```

## Related

- [wait-for-localhost-cli](https://github.com/sindresorhus/wait-for-localhost-cli) - CLI for this module
- [delay](https://github.com/sindresorhus/delay) - Delay execution for a given amount of seconds

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