Package Exports
- is-online
- is-online/browser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-online) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is-online 
Check if the internet connection is up
Works in Node.js and the browser (with browserify/webpack).
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
const isOnline = require('is-online');
isOnline().then(online => {
console.log(online);
//=> true
});
API
isOnline([options])
options
Type: Object
timeout
Type: number
Default: 2000
Milliseconds to wait for a server to respond.
hostnames
Type: string
Array
Default: ['www.google.com', 'www.cloudflare.com', 'www.baidu.com', 'www.yandex.ru']
One or more hosts to check.
How it works
In Node.js, 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 two seconds, we return an offline status. In the rare case where a firewall intercepts the packet and answers 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 connect, we return online, otherwise offline status.
In the browser, a sophisticated check like in Node.js 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 these checks succeed, we return online status. If all the requests fail, we return offline status.
Maintainers
Related
- is-online-cli - CLI for this module
- is-reachable - Check if servers are reachable
License
MIT © Sindre Sorhus