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-online

v12.0.2

Published

Check if the internet connection is up

Downloads

514,974

Readme

is-online

Check if the internet connection is up

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

In the browser, there is already navigator.onLine, but it's useless as it only tells you if there's a local connection, and not whether the internet is accessible.

Install

npm install is-online

Requirements

  • Node.js 20+
  • Works in modern browsers when bundled (requires fetch API support)

Usage

import isOnline from 'is-online';

console.log(await isOnline());
//=> true

With timeout

import isOnline from 'is-online';

console.log(await isOnline({timeout: 10_000}));
//=> true

With abort signal

import isOnline from 'is-online';

const controller = new AbortController();

setTimeout(() => {
	controller.abort();
}, 500);

const result = await isOnline({
	timeout: 3000,
	signal: controller.signal
});

console.log(result);
//=> false

With fallback URLs

import isOnline from 'is-online';

const result = await isOnline({
	fallbackUrls: [
		'https://www.google.com',
		'https://www.github.com',
		'http://example.com'
	]
});

console.log(result);
//=> true

API

isOnline(options?)

Returns a Promise<boolean> that resolves to true if the internet connection is up, false otherwise.

options

Type: object

timeout

Type: number
Default: 5000

Milliseconds to wait for a server to respond.

signal

Type: AbortSignal

An AbortSignal to abort the operation.

When the signal is aborted, the promise will resolve to false.

ipVersion

Type: number
Values: 4 | 6
Default: 4

The Internet Protocol version to use.

This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.

fallbackUrls

Type: string[]

Fallback URLs to check for connectivity.

Only HTTP and HTTPS URLs are supported. In Node.js, these URLs are checked only if all default connectivity checks fail. In the browser, these URLs are checked in parallel with the default checks for better resilience against ad blockers.

How it works

The following checks are run in parallel:

Node.js:

  • Retrieve icanhazip.com (or ipify.org as fallback) via HTTPS.
  • Query myip.opendns.com and o-o.myaddr.l.google.com DNS entries.
  • Retrieve Apple's Captive Portal test page (this is what iOS does).
  • Check Cloudflare's website via HTTPS.

Browser:

When any check succeeds, the returned Promise is resolved to true.

If all the above checks fail and you have provided fallbackUrls, those will be checked as a fallback. The URLs are checked by making HTTP/HTTPS requests (HEAD requests when possible, with GET as fallback).

Diagnostics

The package publishes diagnostic information when connectivity checks fail using Node.js Diagnostics Channel. This is useful for debugging network issues and is only available in Node.js environments.

import {subscribe} from 'node:diagnostics_channel';
import isOnline from 'is-online';

// Subscribe to failure events
subscribe('is-online:connectivity-check', message => {
	console.log('Failed URL:', message.url);
	console.log('Error:', message.error);
});

await isOnline();

Each failure event includes:

  • timestamp - When the failure occurred
  • url - The specific URL that failed
  • error - Error details (name, message, code)

Proxy support

To make it work through proxies, you need to set up global-agent.

Maintainers

Related