wait-port is a utility for Node.js environments designed to asynchronously wait for a network port, HTTP endpoint, or DNS record to become available. It is particularly useful in scripting scenarios, such as `docker-compose` setups, CI/CD pipelines, or application startup scripts, where service dependencies need to be met before proceeding. The package provides both a command-line interface (CLI) and a programmatic API. The current stable version is 1.1.0, released in September 2023, indicating an active development and maintenance cadence. Key features include configurable timeouts, support for TCP, HTTP (checking for 200-class status codes), and DNS resolution (`ENOTFOUND` handling), and robust IPv4/IPv6 support, including 'happy eyeballs' via `autoSelectFamily` introduced in v1.1.0. It distinguishes itself by its simplicity and dual usage model, making it a reliable choice for ensuring service readiness.
npm install wait-portVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic use of `wait-port` to check for a port's availability with a timeout and handles both success and failure.
Update your code to destructure the returned object, e.g., `const { open, ipVersion } = await waitPort(params);` and check `open` for status.Upgrade to version 0.2.14 for compatibility with Node 8, or 0.3.0/higher for Node 10+ compatibility.
Use the `--wait-for-dns` CLI parameter or set `waitForDns: true` in the API options to instruct `wait-port` to continue waiting even if the address is not initially resolvable.
When using the CLI in scripts, ensure you check the process exit code for robust error handling. For the API, catch exceptions and check the `open` property of the returned object.
Increase the timeout duration using the `-t <milliseconds>` flag (e.g., `wait-port -t 30000 localhost:3000`) or ensure the target service is actually starting within a reasonable timeframe.
Verify the hostname/IP address. If waiting for DNS propagation, use `wait-port --wait-for-dns <target>` to make it retry DNS resolution.
For ESM, use `import waitPort from 'wait-port';`. For CommonJS, use `const waitPort = require('wait-port');`.Review the error message for details. Ensure `host` and `port` parameters are valid. Check network connectivity and firewall rules. Increase verbosity if possible (though `wait-port` itself doesn't have a verbose mode for the API beyond `output: 'dots'`).
No dependency data recorded yet.