What is @types/wait-on?
@types/wait-on is a TypeScript type definition package for the wait-on library, which is used to wait for various resources to become available before proceeding. This can include HTTP(s) endpoints, TCP ports, file paths, and more.
What are @types/wait-on's main functionalities?
Wait for HTTP(s) endpoints
This feature allows you to wait for HTTP or HTTPS endpoints to become available. The code sample demonstrates how to wait for a local server and an external website to be accessible.
const waitOn = require('wait-on');
const opts = {
resources: [
'http://localhost:3000',
'https://example.com'
]
};
waitOn(opts, function (err) {
if (err) { return handleError(err); }
// HTTP(s) endpoints are now available
});
Wait for TCP ports
This feature allows you to wait for a specific TCP port to be available. The code sample demonstrates how to wait for a TCP port on localhost.
const waitOn = require('wait-on');
const opts = {
resources: [
'tcp:localhost:8080'
]
};
waitOn(opts, function (err) {
if (err) { return handleError(err); }
// TCP port is now available
});
Wait for file paths
This feature allows you to wait for a specific file path to become available. The code sample demonstrates how to wait for a file to be created or become accessible.
const waitOn = require('wait-on');
const opts = {
resources: [
'file:/path/to/file.txt'
]
};
waitOn(opts, function (err) {
if (err) { return handleError(err); }
// File path is now available
});
Wait for multiple resources
This feature allows you to wait for multiple types of resources simultaneously. The code sample demonstrates how to wait for an HTTP endpoint, a TCP port, and a file path all at once.
const waitOn = require('wait-on');
const opts = {
resources: [
'http://localhost:3000',
'tcp:localhost:8080',
'file:/path/to/file.txt'
]
};
waitOn(opts, function (err) {
if (err) { return handleError(err); }
// All resources are now available
});
Other packages similar to @types/wait-on
wait-for-it
wait-for-it is a pure bash script that will wait on the availability of a host and TCP port. It is useful for shell scripting and is more lightweight compared to wait-on, but it does not support waiting for HTTP endpoints or file paths.
wait-for-localhost
wait-for-localhost is a Node.js package that waits for localhost to be ready. It is simpler and more focused compared to wait-on, as it only supports waiting for localhost and does not handle other types of resources like file paths or external HTTP endpoints.
tcp-ping
tcp-ping is a Node.js package that pings a TCP port to check its availability. It is more specialized compared to wait-on, focusing solely on TCP ports and not supporting other resource types like HTTP endpoints or file paths.