# is-internet-available

> Checks if internet is available using http2, node v8.4.0+ only

Latest version **3.1.0** (published 2022-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-internet-available
pnpm add is-internet-available
yarn add is-internet-available
bun add is-internet-available
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2022-06-27 |
| First published | 2020-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | javad mnjd |
| Maintainers | jdmnjd |
| Keywords | connection, connectivity, is, internet, connected, network, reachable, reachability, detect, online, is-online, offline |

## Links

- npm: https://www.npmjs.com/package/is-internet-available
- Repository: https://github.com/jd1378/is-internet-available
- Homepage: https://github.com/jd1378/is-internet-available#readme
- Issues: https://github.com/jd1378/is-internet-available/issues
- npm.io page: https://npm.io/package/is-internet-available

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.19

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2022-06-27
- 3.0.0 — 2020-04-04
- 2.1.1 — 2020-04-03
- 2.1.0 — 2020-04-02
- 2.0.0 — 2020-03-30
- 1.0.1 — 2020-03-28
- 1.0.0 — 2020-03-28

## README

# is-internet-available

Checks if internet is available using http2, node v8.4.0+ only

## description

By default this package relies on www.google.com being available and certificate stores not be broken because it uses http2 connection for the test.

You can use any other URL for the test

Please check changelogs after each release

It has two exports:

### function `isInternetAvailable` ({ authority?: '<https://www.google.com>', options?: undefined })

* returns a Promise that resolves to true or false

### class `InternetAvailabilityService` (rate?: 10 * 1000, authority?: '<https://www.google.com>', options?: undefined )

* emits `'status'` (`true`|`false`) - (only when it changes)
* emits `'checking'` - when starting to run the check

## usage

First add package to project:

```bash
npm install is-internet-available
# or
yarn add is-internet-available
```

Then use it:

```js
const { isInternetAvailable, InternetAvailabilityService } = require('is-internet-available');

isInternetAvailable().then(console.log);
// or
const service = new InternetAvailabilityService();
service.on('status', (status) => {
  if (status) {
    console.log('internet is now connected');
  } else {
    console.log('internet is now disconnected');
  }
});
```

You can also use against a custom Authority:

```js
const { isInternetAvailable, InternetAvailabilityService } = require('is-internet-available');

isInternetAvailable({ authority: 'http://localhost' }).then(console.log);
// or
const service = new InternetAvailabilityService({
  authority: 'http://localhost',
  rate: 1000, // the wait time between checks
  // options: {
    // options that you may want to pass to http2.connect method
  //}
});

service.on('status', (status) => {
  if (status) {
    console.log('localhost is now available');
  } else {
    console.log('localhost is now unavailable');
  }
});

```

## changelog

### version 3.0.0

Breaking changes:

* corrected options naming to match node's http2.connect method
* now accepts options to pass to the http2.connect method

### version 2.1.1

* updated package.json keywords to help find it easier

### version 2.1.0

Features:

* Can use custom url for testing instead of google

### version 2.0.0

Features:

* added service.

breaking changes:

* no longer exports the function by default

---
_Source: https://npm.io/package/is-internet-available · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
