Nonsense Placement Mandatory
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

is-reachable

3.0.0 • Public • Published

is-reachable Build Status

Check if servers are reachable

Works in Node.js and the browser (with a bundler).

The 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.

The 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.

Install

$ npm install is-reachable

Usage

const isReachable = require('is-reachable');
 
(async () => {
    console.log(await isReachable('sindresorhus.com'));
    //=> true
 
    console.log(await isReachable('google.com:80'));
    //=> true
})();

API

isReachable(targets, [options])

Returns a Promise for a boolean which is true if any of the targets are reachable.

targets

Type: string string[]

One or more targets to check. Can either be a full URL like https://hostname, hostname:port or just hostname. When the protocol is missing from a target http is assumed.

Well-known protocols are supported (e.g. ftp://, mysql://, redis:// and more).

options

Type: Object

timeout

Type: number

Timeout in milliseconds after which a request is considered failed. Default: 5000.

Contributors

Related

  • is-online - Check if the internet connection is up

License

MIT © Sindre Sorhus

install

npm i is-reachable

Downloadsweekly downloads

18,398

version

3.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability