is-online
Check if the internet connection is up
Last updated 5 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install is-online 
SYNC missed versions from official npm registry.

is-online

Check if the internet connection is up

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

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

Usage

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

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

API

isOnline(options?)

options

Type: object

timeout

Type: number
Default: 5000

Milliseconds to wait for a server to respond.

ipVersion

Type: number
Values: 4 | 6
Default: 4

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.

How it works

The following checks are run in parallel:

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

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

Proxy support

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

Maintainers

Related

Current Tags

  • 9.0.1                                ...           latest (5 years ago)

33 Versions

  • 9.0.1                                ...           5 years ago
  • 9.0.0                                ...           5 years ago
  • 8.5.1                                ...           5 years ago
  • 8.5.0                                ...           6 years ago
  • 8.4.0                                ...           6 years ago
  • 8.3.1                                ...           6 years ago
  • 8.3.0                                ...           6 years ago
  • 8.2.2                                ...           6 years ago
  • 8.2.1                                ...           6 years ago
  • 8.2.0                                ...           7 years ago
  • 8.1.0                                ...           7 years ago
  • 8.0.0                                ...           7 years ago
  • 7.0.0                                ...           9 years ago
  • 6.1.0                                ...           9 years ago
  • 6.0.1                                ...           9 years ago
  • 6.0.0                                ...           9 years ago
  • 5.2.0                                ...           9 years ago
  • 5.1.2                                ...           10 years ago
  • 5.1.1                                ...           10 years ago
  • 5.1.0                                ...           10 years ago
  • 5.0.1                                ...           10 years ago
  • 5.0.0                                ...           11 years ago
  • 4.0.2                                ...           11 years ago
  • 4.0.1                                ...           11 years ago
  • 4.0.0                                ...           11 years ago
  • 3.2.0                                ...           11 years ago
  • 3.1.2                                ...           11 years ago
  • 3.1.1                                ...           11 years ago
  • 3.1.0                                ...           11 years ago
  • 3.0.0                                ...           12 years ago
  • 2.0.1                                ...           12 years ago
  • 2.0.0                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |