Learn how to install this module on your project.

To install internet-available on your project, execute the following command in your command line to install it via NPM:

npm install internet-available --save

Once the installation finishes, you will be able to require it in your JavaScript code using require("internet-available").

Options

  • timeout: the allowed time of execution in milliseconds to resolve the DNS address. If the script reaches the limit, then it will be interpreted as a non available connection (default 5000).
  • retries: how many times should the script try to connect if the connection didn't succeed (default 5).
  • domainName: by default used the google.com domain to solve. It can be changed by a custom domain.
  • port: the port to resolve the DNS address (by default 53).
  • host: DNS Host where lookup should check by default '8.8.8.8' (Google Public DNS)

The following example modifies all the properties and uses Our Code World as the domain to resolve:

internetAvailable({
    timeout: 4000,
    retries: 10,
    domainName: "ourcodeworld.com",
    port: 53,
    host: '8.8.8.8'
}).then(() => {
    console.log("Internet available");
}).catch(() => {
    console.log("No internet");
});