JSPM

is-link-working

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 116
  • Score
    100M100P100Q70410F
  • License MIT

Checks if a given link is working or broken

Package Exports

  • is-link-working

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-link-working) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

is-link-working

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

Checks if a given hypermedia link is working or broken (2xx).

Performs a GET request, aborting it as soon as we got the response headers. If the URL is unreachable, checks if you are offline to avoid returning false negatives.

Installation

$ npm install is-link-working

Usage

isLinkWorking(url, options) -> Promise

const isLinkWorking = require('is-link-working');

isLinkWorking('http://google.com')
.then((working) => console.log('working', working))
.catch((err) => console.log('err while checking', err));

Available options:

  • checkConnectivity - True to check internet connectivity if the request fails because of a network error (defaults to true)
  • followRedirect - Defines if redirect responses should be followed automatically (defaults to true)
  • timeout - Milliseconds to wait for a server to send response headers before aborting request with ETIMEDOUT error (defaults to 10000)
  • retries - Number of request retries when network errors happens, see got retries option for more information (defaults to 3)
  • agent - The agent to use, see https://nodejs.org/api/http.html#http_http_request_options_callback (defaults to null)

Connectivity status (online/offline) is made with is-online and its result is cached for 5000 ms to avoid calling it too many times. You may tweak that if you want:

isLinkWorking.connectivityCacheDuration = 0;  // No cache

Tests

$ npm test
$ npm test-cov to get coverage report

License

Released under the MIT License.