{"name":"is-online","version":"12.0.2","description":"Check if the internet connection is up","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/is-online.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"contributors":[{"name":"silverwind","email":"me@silverwind.io","url":"github.com/silverwind"}],"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && node --test && tsd"},"keywords":["browser","online","offline","is-online","network","connected","connectivity","internet","is","has","detect","hostname","hostnames","dns","socket","reachable","reachability","accessible","no","disconnected"],"dependencies":{"fetch-extras":"^1.0.0","p-any":"^4.0.0","p-timeout":"^6.1.4","public-ip":"^7.0.1"},"devDependencies":{"tsd":"^0.33.0","xo":"^1.2.2"},"gitHead":"5904af5993545bc03a7aa58aea58490ba1b9d8e8","types":"./index.d.ts","_id":"is-online@12.0.2","bugs":{"url":"https://github.com/sindresorhus/is-online/issues"},"homepage":"https://github.com/sindresorhus/is-online#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"integrity":"sha512-aMN8oxroDeWTyio61kRQOlldQO1+BQp3JfdHMZD8R20oCtL/KZV4eUGUTy9gnuKOm7g6N49wXwLD9OIPi7qWmQ==","shasum":"c6bc1a6d28d86a3ed968c75b263bd63f2980e16f","tarball":"http://registry-npm.ywwl.com/is-online/download/is-online-12.0.2.tgz","fileCount":6,"unpackedSize":16733,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDUlc4/eRMt/nNBaeM5N2BifL13ml6pa4dLm99gcKvs/wIgUVJcc+1nyWiefXrS48ZVGFiVXCeX7nmPmbilmAc+Wo0="}],"size":5416,"noattachment":false,"key":"/is-online/-/is-online-12.0.2.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/is-online_12.0.2_1763197932902_0.7109040113794021"},"_hasShrinkwrap":false,"readme":"# is-online\n\n> Check if the internet connection is up\n\nWorks in Node.js and the browser *(with a bundler)*.\n\nIn the browser, there is already [`navigator.onLine`](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine), but it's useless as it only tells you if there's a local connection, and not whether the internet is accessible.\n\n## Install\n\n```sh\nnpm install is-online\n```\n\n## Requirements\n\n- Node.js 20+\n- Works in modern browsers when bundled (requires `fetch` API support)\n\n## Usage\n\n```js\nimport isOnline from 'is-online';\n\nconsole.log(await isOnline());\n//=> true\n```\n\n### With timeout\n\n```js\nimport isOnline from 'is-online';\n\nconsole.log(await isOnline({timeout: 10_000}));\n//=> true\n```\n\n### With abort signal\n\n```js\nimport isOnline from 'is-online';\n\nconst controller = new AbortController();\n\nsetTimeout(() => {\n\tcontroller.abort();\n}, 500);\n\nconst result = await isOnline({\n\ttimeout: 3000,\n\tsignal: controller.signal\n});\n\nconsole.log(result);\n//=> false\n```\n\n### With fallback URLs\n\n```js\nimport isOnline from 'is-online';\n\nconst result = await isOnline({\n\tfallbackUrls: [\n\t\t'https://www.google.com',\n\t\t'https://www.github.com',\n\t\t'http://example.com'\n\t]\n});\n\nconsole.log(result);\n//=> true\n```\n\n## API\n\n### isOnline(options?)\n\nReturns a `Promise<boolean>` that resolves to `true` if the internet connection is up, `false` otherwise.\n\n#### options\n\nType: `object`\n\n##### timeout\n\nType: `number`\\\nDefault: `5000`\n\nMilliseconds to wait for a server to respond.\n\n##### signal\n\nType: `AbortSignal`\n\nAn [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to abort the operation.\n\nWhen the signal is aborted, the promise will resolve to `false`.\n\n##### ipVersion\n\nType: `number`\\\nValues: `4 | 6`\\\nDefault: `4`\n\nThe [Internet Protocol version](https://en.wikipedia.org/wiki/Internet_Protocol#Version_history) to use.\n\nThis is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.\n\n##### fallbackUrls\n\nType: `string[]`\n\nFallback URLs to check for connectivity.\n\nOnly 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.\n\n## How it works\n\nThe following checks are run in parallel:\n\n**Node.js:**\n- Retrieve [icanhazip.com](https://github.com/major/icanhaz) (or [ipify.org](https://www.ipify.org) as fallback) via HTTPS.\n- Query `myip.opendns.com` and `o-o.myaddr.l.google.com` DNS entries.\n- Retrieve Apple's Captive Portal test page (this is what iOS does).\n- Check Cloudflare's website via HTTPS.\n\n**Browser:**\n- Retrieve [icanhazip.com](https://github.com/major/icanhaz) (or [ipify.org](https://www.ipify.org) as fallback) via HTTPS.\n\nWhen any check succeeds, the returned Promise is resolved to `true`.\n\nIf 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).\n\n## Diagnostics\n\nThe package publishes diagnostic information when connectivity checks fail using Node.js [Diagnostics Channel](https://nodejs.org/api/diagnostics_channel.html#diagnostics-channel). This is useful for debugging network issues and is only available in Node.js environments.\n\n```js\nimport {subscribe} from 'node:diagnostics_channel';\nimport isOnline from 'is-online';\n\n// Subscribe to failure events\nsubscribe('is-online:connectivity-check', message => {\n\tconsole.log('Failed URL:', message.url);\n\tconsole.log('Error:', message.error);\n});\n\nawait isOnline();\n```\n\nEach failure event includes:\n- `timestamp` - When the failure occurred\n- `url` - The specific URL that failed\n- `error` - Error details (name, message, code)\n\n## Proxy support\n\nTo make it work through proxies, you need to set up [`global-agent`](https://github.com/gajus/global-agent).\n\n## Maintainers\n\n- [Sindre Sorhus](https://github.com/sindresorhus)\n- [silverwind](https://github.com/silverwind)\n\n## Related\n\n- [is-online-cli](https://github.com/sindresorhus/is-online-cli) - CLI for this module\n- [is-reachable](https://github.com/sindresorhus/is-reachable) - Check if servers are reachable\n","publish_time":1763197933120,"_cnpm_publish_time":1763197933120,"dist-tags":{"latest":"12.0.2"}}