UNPKG

1.25 kBTypeScriptView Raw
1declare namespace isReachable {
2 interface Options {
3 /**
4 Timeout in milliseconds after which a request is considered failed.
5
6 @default 5000
7 */
8 readonly timeout?: number;
9 }
10}
11
12/**
13Check if servers are reachable.
14
15The Node.js version will do a TCP handshake with the target's port. It attempts to detect cases where a router redirects the request to itself.
16
17The browser version is limited by the fact that browsers cannot connect to arbitrary ports. It only supports HTTP and HTTPS and the check relies on the `/favicon.ico` path being present.
18
19@param targets - One or more targets to check. Can either be `hostname:port`, a URL like `https://hostname:port` or even just `hostname`. `port` must be specified if protocol is not `http:` or `https:` and defaults to `443`. Protocols other than `http:` and `https:` are not supported.
20@returns Whether any of the `targets` are reachable.
21
22@example
23```
24import isReachable = require('is-reachable');
25
26(async () => {
27 console.log(await isReachable('sindresorhus.com'));
28 //=> true
29
30 console.log(await isReachable('google.com:80'));
31 //=> true
32})();
33```
34*/
35declare function isReachable(
36 targets: string | readonly string[],
37 options?: isReachable.Options
38): Promise<boolean>;
39
40export = isReachable;