Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/wait-for-localhost
Wait for localhost to be ready
https://github.com/sindresorhus/wait-for-localhost
delay localhost nodejs npm-package server wait
Last synced: 4 days ago
JSON representation
Wait for localhost to be ready
- Host: GitHub
- URL: https://github.com/sindresorhus/wait-for-localhost
- Owner: sindresorhus
- License: mit
- Created: 2018-05-23T09:32:50.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-17T18:22:54.000Z (7 months ago)
- Last Synced: 2024-12-17T11:33:44.636Z (5 days ago)
- Topics: delay, localhost, nodejs, npm-package, server, wait
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 274
- Watchers: 6
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome - sindresorhus/wait-for-localhost - Wait for localhost to be ready (JavaScript)
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.
## 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` that settles when localhost is ready.
The object contains a `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.
## 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