Install wait-on
masterYou can install wait-on either locally to your project or globally on your system using npm.
npm install wait-on # local version
OR
npm install -g wait-on # global versionrepository·master·Indexed 24 days ago
https://github.com/jeffbski/wait-onA cross-platform command line utility and Node.js API (version 9.1.0) used to wait for files, ports, sockets, and http(s) resources to become available. It is commonly used to synchronize tasks in build pipelines or service orchestration, supporting resource prefixes such as file:, http:, https:, tcp:, and socket:.
You can install wait-on either locally to your project or globally on your system using npm.
npm install wait-on # local version
OR
npm install -g wait-on # global versionThe wait-on CLI utility waits for files, ports, sockets, or HTTP(S) resources to become available. It exits with code 0 when all resources are ready, or a non-zero code if interrupted or timed out. You can combine it with other commands in a shell using && to run a command only after the resources are ready.
Resource Types and Prefixes:
Resources are identified by prefixes. If no prefix is provided, it is assumed to be a file.
file:: A regular file (default). Example: file:/path/to/filehttp:: HTTP HEAD returns a 2XX response. Example: http://m.com:90/foohttps:: HTTPS HEAD returns a 2XX response. Example: https://my/barhttp-get:: HTTP GET returns a 2XX response. Example: http-get://m.com:90/foohttps-get:: HTTPS GET returns a 2XX response. Example: https-get://my/bartcp:: A TCP port is listening. Example: tcp:1.2.3.4:9000 or tcp:foo.com:700socket:: A Domain Socket is listening. Example: socket:/path/to/sockhttp://unix:SOCK_PATH:URL_PATH. Example: http://unix:/path/to/sock:http://server/foo/barThe wait-on CLI utility waits for specified resources to become available. Once all resources are ready, it exits with code 0, allowing you to chain subsequent commands using &&. If resources are not available within the timeout or are interrupted, it exits with a non-zero code, preventing the next command from running.
Common usage patterns include waiting for files, HTTP endpoints, TCP ports, or Unix domain sockets.
wait-on file1 && NEXT_CMD # wait for file1, then exec NEXT_CMD
wait-on f1 f2 && NEXT_CMD # wait for both f1 and f2, then exec NEXT_CMD
wait-on http://localhost:8000/foo && NEXT_CMD # wait for http 2XX HEAD
wait-on tcp:4000 && NEXT_CMD # wait for service to listen on a TCP port
wait-on socket:/path/mysock # wait for service to listen on domain socket--config flag. This is particularly useful for complex HTTP(S) options. The contents of the config file are required and merged with any command line options provided.When using flags like --timeout, --interval, --httpTimeout, or --tcpTimeout, you can provide values as strings with time units. The CLI parses these into milliseconds.
Supported units:
ms: Milliseconds (e.g., 500 or 500ms)s: Seconds (e.g., 5s)m: Minutes (e.g., 1m)h: Hours (e.g., 1h)You can use wait-on programmatically in your Node.js applications. It supports callbacks, Promises, and async/await syntax. The waitOn(opts) function accepts an options object to configure resources and polling behavior.
var waitOn = require('wait-on');
var opts = {
resources: [
'file1',
'http://foo.com:8000/bar',
'tcp:foo.com:8000'
],
delay: 1000,
interval: 100,
timeout: 30000
};
// Usage with async await
try {
await waitOn(opts);
// once here, all resources are available
} catch (err) {
handleError(err);
}When waiting for HTTP or HTTPS resources via the Node.js API, you can pass advanced configuration options (similar to TLS options or Axios config) within the opts object.
var opts = {
resources: ['http://foo.com:8000/bar'],
// http options
ca: [/* strings or binaries */],
cert: [/* strings or binaries */],
key: [/* strings or binaries */],
passphrase: 'yourpassphrase',
proxy: {
host: '127.0.0.1',
port: 9000,
auth: { username: 'mikeymike', password: 'rapunz3l' }
},
auth: { user: 'theuser', pass: 'thepassword' },
strictSSL: false,
followRedirect: true,
headers: { 'x-custom': 'headers' },
validateStatus: function (status) {
return status >= 200 && status < 300;
}
};When using the CLI or the Node.js API, you specify the type of resource using a prefix. If no prefix is provided, the resource is assumed to be a file.
file: - regular file (also default type). ex: file:/path/to/file
http: - HTTP HEAD returns 2XX response. ex: http://m.com:90/foo
https: - HTTPS HEAD returns 2XX response. ex: https://my/bar
http-get: - HTTP GET returns 2XX response. ex: http://m.com:90/foo
https-get: - HTTPS GET returns 2XX response. ex: https://my/bar
tcp: - TCP port is listening. ex: 1.2.3.4:9000 or foo.com:700
socket: - Domain Socket is listening. ex: socket:/path/to/sock
For http over socket, use http://unix:SOCK_PATH:URL_PATH
like http://unix:/path/to/sock:http://server/foo/barThe following options are available for the wait-on command line utility:
-c, --config
js or json config file, useful for http(s) options
-d, --delay
Initial delay before checking for resources in ms, default 0
--httpTimeout
Maximum time in ms to wait for an HTTP HEAD/GET request, default 0
which results in using the OS default
-i, --interval
Interval to poll resources in ms, default 250ms
-l, --log
Log resources begin waited on and when complete or errored
-r, --reverse
Reverse operation, wait for resources to NOT be available
-s, --simultaneous
Simultaneous / Concurrent connections to a resource, default Infinity
Setting this to 1 would delay new requests until previous one has completed.
Used to limit the number of connections attempted to a resource at a time.
-t, --timeout
Maximum time in ms to wait before exiting with failure (1) code,
default Infinity
Use postfix 'ms', 's', 'm' or 'h' to change the unit.
--tcpTimeout
Maximum time in ms for tcp connect, default 300ms
Use postfix 'ms', 's', 'm' or 'h' to change the unit.
--httpTimeout
Maximum time to wait for the HTTP request, default Infinity
Use postfix 'ms', 's', 'm' or 'h' to change the unit.
-v, --verbose
Enable debug output to stdout
-w, --window
Stability window, the time in ms defining the window of time that
resource needs to have not changed (file size/availability) before
signaling success, default 750ms. If less than interval, it will be
reset to the value of interval. This is only used for files, other
resources are considered available on first detection.
-h, --help
Show this messageThe wait-on CLI supports several options to control behavior, timeouts, and polling.
-c, --config js or json config file
-d, --delay Initial delay before checking for resources in ms, default 0
--httpTimeout Maximum time in ms to wait for an HTTP HEAD/GET request, default 0
-i, --interval Interval to poll resources in ms, default 250ms
-l, --log Log resources begin waited on and when complete or errored
-r, --reverse Reverse operation, wait for resources to NOT be available
-s, --simultaneous Simultaneous / Concurrent connections to a resource, default Infinity
-t, --timeout Maximum time in ms to wait before exiting with failure (1), default Infinity
--tcpTimeout Maximum time in ms for tcp connect, default 300ms
-v, --verbose Enable debug output to stdout
-w, --window Stability window, the time in ms defining the window of time that resource needs to have not changed before signalling success, default 750ms
-h, --help Show this messageThe following flags can be used to control the behavior of the wait-on CLI. Note that some flags have aliases.
| Flag | Alias | Type | Description |
|---|---|---|---|
--config | -c | string | Path to a JS/JSON configuration file. |
--delay | -d | string | Delay before starting to check resources. |
--interval | -i | string | Interval between checks. Supports time units (ms, s, m, h). |
--log | -l | boolean | Enable logging. |
--reverse | -r | boolean | Wait for resources to become unavailable instead of available. |
--simultaneous | -s | boolean | Wait for all resources to be available (default is waiting for any). |
--timeout | -t | string | Total timeout for the entire operation. Supports time units (ms, s, m, h). |
--verbose | -v | boolean | Enable verbose output. |
--window | -w | string | Window of time for resource availability. |
--httpTimeout | string | Specific timeout for HTTP resources. Supports time units (ms, s, m, h). | |
--tcpTimeout | string | Specific timeout for TCP/socket resources. Supports time units (ms, s, m, h). | |
--help | -h | boolean | Display help/usage information. |
The wait-on CLI allows you to pause execution until specific files, ports, sockets, or HTTP(S) resources become available. You can pass resources directly as command-line arguments or via a configuration file.
Precedence Rules:
resources array is found in the config file, the CLI will display the usage information and exit.