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.
npm install is-online
import isOnline from 'is-online'; console.log(await isOnline()); //=> true
Milliseconds to wait for a server to respond.
4 | 6
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.
How it works
The following checks are run in parallel:
- Retrieve icanhazip.com (or ipify.org as fallback) via HTTPS.
o-o.myaddr.l.google.comDNS 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
To make it work through proxies, you need to set up