npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

is-reachable

v6.0.0

Published

Check if servers are reachable

Readme

is-reachable

Check if servers are reachable

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

The Node.js version uses HTTP HEAD/GET requests for HTTP(S) URLs and TCP connections for other ports. For HTTP(S), it tries HEAD requests first (for better performance and bandwidth efficiency), falling back to GET requests if HEAD is not supported. 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 tries to load common favicon paths (/favicon.ico, /favicon.png, /favicon.svg, /apple-touch-icon.png, /apple-touch-icon-precomposed.png) to determine reachability. The browser version does not support the requireHttpSuccess option and will only return true if the favicon files load successfully (equivalent to requireHttpSuccess: true).

[!IMPORTANT] By default, any HTTP response (including 404, 401, 403, 500, etc.) is considered “reachable” since it proves the server is responding. This aligns with the network-level definition of reachability. Use the requireHttpSuccess option if you need to check for successful responses only.

Install

npm install is-reachable

Usage

import isReachable from 'is-reachable';

console.log(await isReachable('sindresorhus.com'));
//=> true

console.log(await isReachable('google.com:443'));
//=> true

// With timeout
console.log(await isReachable('sindresorhus.com', {
	signal: AbortSignal.timeout(3000)
}));
//=> true

API

isReachable(targets, options?)

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

targets

Type: string | string[]

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.

options

Type: object

signal

Type: AbortSignal

An AbortSignal to cancel the requests.

You can use AbortSignal.timeout() to create a signal that automatically aborts after a specified time:

await isReachable('sindresorhus.com', {
	signal: AbortSignal.timeout(3000)
});

Or combine multiple signals using AbortSignal.any():

const controller = new AbortController();
const timeoutSignal = AbortSignal.timeout(5000);

await isReachable('example.com', {
	signal: AbortSignal.any([controller.signal, timeoutSignal])
});
requireHttpSuccess

Type: boolean
Default: false

Only consider the server reachable if it returns a successful HTTP status code (200-299).

When false (default), any HTTP response (including 4xx and 5xx) is considered reachable, as it proves the server is responding. This aligns with the network-level definition of "reachability".

When true, only successful HTTP responses (2xx status codes) are considered reachable, which is useful for application health checks.

Related

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

Maintainers