Gathering detailed insights and metrics for wait-on
Gathering detailed insights and metrics for wait-on
Gathering detailed insights and metrics for wait-on
Gathering detailed insights and metrics for wait-on
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
npm install wait-on
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,871 Stars
222 Commits
77 Forks
11 Watching
19 Branches
19 Contributors
Updated on 29 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-24.6%
600,164
Compared to previous day
Last week
-5.7%
3,894,726
Compared to previous week
Last month
2.1%
17,296,197
Compared to previous month
Last year
11.5%
182,208,828
Compared to previous year
wait-on is a cross-platform command line utility which will wait for files, ports, sockets, and http(s) resources to become available (or not available using reverse mode). Functionality is also available via a Node.js API. Cross-platform - runs everywhere Node.js runs (linux, unix, mac OS X, windows)
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 or GET requests (after following any redirects).
wait-on can also be used in reverse mode which waits for resources to NOT be available. This is useful in waiting for services to shutdown before continuing. (Thanks @skarbovskiy for adding this feature)
Latest wait-on version 7+ requires Node.js 12+ wait-on versions 4-6 requires Node.js 10+
(Node.js v8 users can use wait-on@5.3.0, v4 users can still use wait-on@2.1.2, and older Node.js engines, use wait-on@1.5.4)
1npm install wait-on # local version 2OR 3npm 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 a successful exit code (0) once all resources are available, causing NEXT_CMD to be run.
wait-on can also be used in reverse mode, which waits for resources to NOT be available. This is useful in waiting for services to shutdown before continuing. (Thanks @skarbovskiy for adding)
If wait-on is interrupted before all resources are available, it will exit with a non-zero exit code and thus NEXT_CMD will not be run.
1wait-on file1 && NEXT_CMD # wait for file1, then exec NEXT_CMD 2wait-on f1 f2 && NEXT_CMD # wait for both f1 and f2, the exec NEXT_CMD 3wait-on http://localhost:8000/foo && NEXT_CMD # wait for http 2XX HEAD 4wait-on https://myserver/foo && NEXT_CMD # wait for https 2XX HEAD 5wait-on http-get://localhost:8000/foo && NEXT_CMD # wait for http 2XX GET 6wait-on https-get://myserver/foo && NEXT_CMD # wait for https 2XX GET 7wait-on tcp:4000 && NEXT_CMD # wait for service to listen on a TCP port 8wait-on socket:/path/mysock # wait for service to listen on domain socket 9wait-on http://unix:/var/SOCKPATH:http://server/a/foo # wait for http HEAD on domain socket 10wait-on http-get://unix:/var/SOCKPATH:http://server/a/foo # wait for http GET 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 (or not available
using reverse flag). Exits with success code (0) when all resources
are ready. Non-zero exit code if interrupted or timed out.
Options may also be specified in a config file (js or json). For
example --config configFile.js would result in configFile.js being
required and the resulting object will be merged with any
command line options before wait-on is called. See exampleConfig.js
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'. Resources
can also be provided in the config 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
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/bar or
http-get://unix:/path/to/sock:http://server/foo/bar
Standard Options:
-c, --config
js or json config file, useful for http(s) options and resources
-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 or availability) before
signalling 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 message
1var waitOn = require('wait-on'); 2var opts = { 3 resources: [ 4 'file1', 5 'http://foo.com:8000/bar', 6 'https://my.com/cat', 7 'http-get://foo.com:8000/bar', 8 'https-get://my.com/cat', 9 'tcp:foo.com:8000', 10 'socket:/my/sock', 11 'http://unix:/my/sock:http://server/my/url', 12 'http-get://unix:/my/sock:http://server/my/url' 13 ], 14 delay: 1000, // initial delay in ms, default 0 15 interval: 100, // poll interval in ms, default 250ms 16 simultaneous: 1, // limit to 1 connection per resource at a time 17 timeout: 30000, // timeout in ms, default Infinity 18 tcpTimeout: 1000, // tcp timeout in ms, default 300ms 19 window: 1000, // stabilization time in ms, default 750ms 20 21 // http options 22 ca: [ 23 /* strings or binaries */ 24 ], 25 cert: [ 26 /* strings or binaries */ 27 ], 28 key: [ 29 /* strings or binaries */ 30 ], 31 passphrase: 'yourpassphrase', 32 proxy: false /* OR proxy config as defined in axios. 33 If not set axios detects proxy from env vars http_proxy and https_proxy 34 https://github.com/axios/axios#config-defaults 35 { 36 host: '127.0.0.1', 37 port: 9000, 38 auth: { 39 username: 'mikeymike', 40 password: 'rapunz3l' 41 } 42 } */, 43 auth: { 44 user: 'theuser', // or username 45 pass: 'thepassword' // or password 46 }, 47 strictSSL: false, 48 followRedirect: true, 49 headers: { 50 'x-custom': 'headers' 51 }, 52 validateStatus: function (status) { 53 return status >= 200 && status < 300; // default if not provided 54 } 55}; 56 57// Usage with callback function 58waitOn(opts, function (err) { 59 if (err) { 60 return handleError(err); 61 } 62 // once here, all resources are available 63}); 64 65// Usage with promises 66waitOn(opts) 67 .then(function () { 68 // once here, all resources are available 69 }) 70 .catch(function (err) { 71 handleError(err); 72 }); 73 74// Usage with async await 75try { 76 await waitOn(opts); 77 // once here, all resources are available 78} catch (err) { 79 handleError(err); 80}
waitOn(opts, [cb]) - function which triggers resource checks
opts.resources - array of string resources to wait for. prefix determines the type of resource with the default type of file:
opts.delay - optional initial delay in ms, default 0
opts.interval - optional poll resource interval in ms, default 250ms
opts.log - optional flag which outputs to stdout, remaining resources waited on and when complete or errored
opts.resources - optional array of string resources to wait for if none are specified via command line
opts.reverse - optional flag to reverse operation so checks are for resources being NOT available, default false
opts.simultaneous - optional count to limit concurrent connections per resource at a time, setting to 1 waits for previous connection to succeed, fail, or timeout before sending another, default infinity
opts.timeout - optional timeout in ms, default Infinity. Aborts with error.
opts.tcpTimeout - optional tcp timeout in ms, default 300ms
opts.verbose - optional flag which outputs debug output, default false
opts.window - optional stabilization time in ms, default 750ms. Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged.
http(s) specific options, see https://nodejs.org/api/tls.html#tls_tls_connect_options_callback for specific details
1 // example proxy object 2 { 3 host: '127.0.0.1', 4 port: 9000, 5 auth: { 6 username: 'mikeymike', 7 password: 'rapunz3l' 8 } 9 }
opts.auth: { user, pass }
opts.strictSSL: false,
opts.followRedirect: false, // defaults to true
opts.headers: { 'x-custom': 'headers' },
cb(err) - if err is provided then, resource checks did not succeed
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:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
9 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More