Cross-platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available
npx @tessl/cli install tessl/npm-wait-on@8.0.0wait-on is a cross-platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available. It provides both a command line interface and programmatic Node.js API with extensive configuration options for monitoring various resource types with customizable timeouts, intervals, and retry logic.
npm install wait-onconst waitOn = require('wait-on');For ES modules:
import waitOn from 'wait-on';const waitOn = require('wait-on');
// Simple file waiting
await waitOn({ resources: ['file:/path/to/file'] });
// Wait for HTTP endpoints
await waitOn({
resources: ['http://localhost:3000', 'https://api.example.com/health']
});
// Wait for multiple resource types
await waitOn({
resources: [
'file:/tmp/app.log',
'tcp:localhost:3000',
'http://localhost:3000/health'
],
timeout: 30000,
interval: 1000
});
// Using callback style
waitOn({
resources: ['http://localhost:8080']
}, (err) => {
if (err) {
console.error('Resource failed to become available:', err);
} else {
console.log('Resources are now available!');
}
});wait-on is built around several key components:
Core programmatic interface for waiting on resources with Promise and callback support. Includes comprehensive configuration options for timeouts, intervals, and HTTP-specific settings.
/**
* Wait for resources to become available
* @param opts - Configuration options
* @param cb - Optional callback function (err) => void
* @returns Promise<void> when cb not provided
*/
function waitOn(opts, cb?): Promise<void> | void;Command-line utility with full access to all wait-on functionality through CLI arguments and configuration files. Supports time interval parsing and environment-specific options.
wait-on [options] resource1 [resource2 ...]Support for multiple resource types including files, HTTP endpoints, TCP ports, and Unix domain sockets. Each resource type has specific behavior and configuration options.
// File resources (default)
'file:/path/to/file'
'/path/to/file'
// HTTP resources
'http://hostname:port/path'
'https://hostname:port/path'
'http-get://hostname:port/path'
'https-get://hostname:port/path'
// TCP port resources
'tcp:hostname:port'
'tcp:port' // defaults to localhost
// Unix socket resources
'socket:/path/to/socket'
// HTTP over Unix socket
'http://unix:/path/to/socket:/url/path'
'http-get://unix:/path/to/socket:/url/path'interface WaitOnOptions {
resources: string[];
delay?: number;
httpTimeout?: number;
interval?: number;
log?: boolean;
reverse?: boolean;
simultaneous?: number;
timeout?: number;
validateStatus?: (status: number) => boolean;
verbose?: boolean;
window?: number;
tcpTimeout?: number;
// HTTP/HTTPS options
ca?: string | Buffer | (string | Buffer)[];
cert?: string | Buffer | (string | Buffer)[];
key?: string | Buffer | object | (string | Buffer | object)[];
passphrase?: string;
proxy?: boolean | {
host: string;
port: number;
auth?: {
username: string;
password: string;
};
};
auth?: {
username: string;
password: string;
};
strictSSL?: boolean;
followRedirect?: boolean;
headers?: object;
}