You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

is-online

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-online

Check if the internet connection is up

Source
npmnpm
Version
4.0.2
Version published
Weekly downloads
180K
7.88%
Maintainers
2
Weekly downloads
 
Created
Source

is-online Build Status

Check if the internet connection is up

Works in Node.js, CLI and the browser (with browserify).

In the browser you have 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 --save is-online

Usage

var isOnline = require('is-online');

isOnline(function(err, online) {
	console.log(online);
	//=> true
});

Node API

isOnline(callback)

callback(error, online)

Required
Type: function

error is there only by Node.js convention and is always null.

Browser API

isOnline(callback)

callback(online)

Required
Type: function

CLI

$ npm install --global is-online
$ is-online --help

  Example
    $ is-online
    ✔︎ Online

How it works

In node, we first contact one of the thirteen root servers and ask them to direct us to the servers which host the <root> zone (Which they are themselves). If the server answers, we return an online status.

If no satisfying answer is given within one second, we return an offline status. In the rare case where an firewall intercepts the packet and answers it on its behalf, a second check is run which tries to connect to a series of popular web sites on port 80. If one of these connects, we return online, otherwise offline status.

In the browser, a sophisticated check like in node is not possible because DNS and sockets are abstracted away. We use a check which requests an uncached favicon.ico on a series of popular websites. If one of this checks succeeds, we return online status. If all the requests fail, we return offline status.

Contributors

  • silverwind

License

MIT © Sindre Sorhus

Keywords

cli-app

FAQs

Package last updated on 13 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts