Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
wait-on is a command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available
The wait-on npm package is a cross-platform command line utility and Node.js API that will wait for files, ports, sockets, and http(s) resources to become available. It is commonly used in automated scripts, such as before starting tests or ensuring that services are up before proceeding with the next steps in a script.
Waiting for files to exist
This feature allows you to wait for one or more files to exist before executing the next part of your script.
const waitOn = require('wait-on');
const opts = {
resources: [
'file1',
'path/to/file2'
]
};
waitOn(opts, function (err) {
if (err) return handleError(err);
// Files are now available
});
Waiting for HTTP resources
This feature allows you to wait for HTTP(s) resources to respond with a successful status code before continuing.
const waitOn = require('wait-on');
const opts = {
resources: [
'http://foo.com:8000/bar'
],
delay: 1000, // initial delay in ms, default 0
interval: 100, // poll interval in ms, default 250ms
timeout: 30000, // timeout in ms, default Infinity
window: 1000 // stabilization time in ms, default 750ms
};
waitOn(opts, function (err) {
if (err) return handleError(err);
// HTTP resource is now available
});
Waiting for TCP ports
This feature allows you to wait for a TCP port to be open, indicating that a service is listening on the specified port.
const waitOn = require('wait-on');
const opts = {
resources: [
'tcp:localhost:8000'
]
};
waitOn(opts, function (err) {
if (err) return handleError(err);
// TCP port is now available
});
Waiting for socket files
This feature allows you to wait for a Unix socket file to be available.
const waitOn = require('wait-on');
const opts = {
resources: [
'socket:/path/to/socket'
]
};
waitOn(opts, function (err) {
if (err) return handleError(err);
// Socket file is now available
});
This package is similar to wait-on as it is used to start a server and then run tests against it. It waits for the server to be available before starting the tests. It is more specialized for the use case of running tests after starting a server, whereas wait-on is more general-purpose.
Concurrently is a package that can run multiple commands concurrently. It's not a direct alternative to wait-on, but it can be used in combination with wait-on to run a server and then wait for it to be ready before executing the next command.
This package provides similar functionality to wait-on, allowing you to wait for files, ports, and processes. It offers a slightly different API and additional options for waiting on processes, which wait-on does not provide.
wait-on is a command line utility which will wait for files, ports, sockets, and http(s) resources to become available. Functionality is also available via a Node.js API
wait-on will wait for period of time for a file to stop growing before triggering availability which is good for monitoring files that are being built. Likewise wait-on will wait for period of time for other resources to remain available before triggering success.
For http(s) resources wait-on will check that the requests are returning 2XX (success) to HEAD requests (after following any redirects).
Requires node.js/iojs >= 0.10
npm install wait-on # local version
OR
npm install -g wait-on # global version
Use from command line or using Node.js programmatic API.
Assuming NEXT_CMD is the command to run when resources are available, then wait-on will wait and then exit with successfull exit code (0) once all resrouces are available causing NEXT_CMD to be run.
If wait-on is interrupted before all resources are available, it will exit with non-zero exit code and thus NEXT_CMD will not be run.
wait-on file1 && NEXT_CMD # wait for file1, then exec NEXT_CMD
wait-on f1 f2 && NEXT_CMD # wait for both f1 and f2, the exec NEXT_CMD
wait-on http://localhost:8000/foo && NEXT_CMD # wait for http 2XX HEAD
wait-on https://myserver/foo && NEXT_CMD # wait for https 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
Usage: wait-on {OPTIONS} resource [...resource]
Description:
wait-on is a command line utility which will wait for files, ports,
sockets, and http(s) resources to become available. Exits with
success code (0) when all resources are ready. Non-zero exit code
if interrupted or timed out.
In shell combine with && to conditionally run another command
once resources are available. ex: wait-on f1 && NEXT_CMD
resources types are defined by their prefix, if no prefix is
present, the resource is assumed to be of type 'file'
resource prefixes are:
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
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:/foo/bar
Standard Options:
-d, --delay
Initial delay before checking for resources in ms, default 0
-i, --interval
Interval to poll resources in ms, default 250ms
-t, --timeout
Maximum time in ms to wait before exiting with failure (1) code,
default Infinity
-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 or availability) before
signalling success, default 750ms. If less than interval, it will be
reset to the value of interval.
-h, --help
Show this message
var waitOn = require('wait-on');
var opts = {
resources: [
'file1',
'http://foo.com:8000/bar',
'https://my.com/cat',
'tcp:foo.com:8000',
'socket:/my/sock'
],
delay: 1000, // initial delay in ms, default 0
interval: 100, // poll interval in ms, default 250ms
timeout: 30000, // timeout in ms, default Infinity
window: 1000, // stabilization time in ms, default 750ms
};
waitOn(opts, function (err) {
if (err) { return handleError(err); }
// once here, all resources are available
});
waitOn(opts, cb) - function which triggers resource checks
file:
I frequently need to wait on build tasks to complete or services to be available before starting next command, so this project makes that easier and is portable to everywhere Node.js runs.
If you have input or ideas or would like to get involved, you may:
FAQs
wait-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
The npm package wait-on receives a total of 3,220,221 weekly downloads. As such, wait-on popularity was classified as popular.
We found that wait-on demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.