Code Monkey home page Code Monkey logo

is-reachable's Introduction

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

is-reachable's People

Contributors

silverwind avatar sindresorhus avatar kevva avatar arthurvr avatar genbandbrent avatar danielmahon avatar jleft avatar johno avatar mmalecki avatar moox avatar ntwb avatar austinkelleher avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.