GithubHelp home page GithubHelp logo

kamaal44 / link-check Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tcort/link-check

0.0 1.0 0.0 249 KB

checks whether a hyperlink is alive (`200 OK`) or dead.

License: ISC License

JavaScript 100.00%

link-check's Introduction

Test library workflow status

link-check

Checks whether a hyperlink is alive (200 OK) or dead.

Installation

npm install --save link-check

Specification

A link is said to be 'alive' if an HTTP HEAD or HTTP GET for the given URL eventually ends in a 200 OK response. To minimize bandwidth, an HTTP HEAD is performed. If that fails (e.g. with a 405 Method Not Allowed), an HTTP GET is performed. Redirects are followed.

In the case of mailto: links, this module validates the e-mail address using isemail.

API

linkCheck(link, [opts,] callback)

Given a link and a callback, attempt an HTTP HEAD and possibly an HTTP GET.

Parameters:

  • url string containing a URL.
  • opts optional options object containing any of the following optional fields:
    • baseUrl the base URL for relative links.
    • timeout timeout in zeit/ms format. (e.g. "2000ms", 20s, 1m). Default 10s.
    • aliveStatusCodes an array of numeric HTTP Response codes which indicate that the link is alive. Entries in this array may also be regular expressions. Example: [ 200, /^[45][0-9]{2}$/ ]. Default [ 200 ].
    • headers a string based attribute value object to send custom HTTP headers. Example: { 'Authorization' : 'Basic Zm9vOmJhcg==' }.
    • retryOn429 a boolean indicating whether to retry on a 429 (Too Many Requests) response. When true, if the response has a 429 HTTP code and includes an optional retry-after header, a retry will be attempted after the delay indicated in the retry-after header. If no retry-after header is present in the response or the retry-after header value is not valid according to RFC7231 (value must be in seconds), a default retry delay of 60 seconds will apply. This default can be overriden by the fallbackRetryDelay parameter.
    • retryCount the number of retries to be made on a 429 response. Default 2.
    • fallbackRetryDelay the delay in zeit/ms format. (e.g. "2000ms", 20s, 1m) for retries on a 429 response when no retry-after header is returned or when it has an invalid value. Default is 60s.
  • callback function which accepts (err, result).
    • err an Error object when the operation cannot be completed, otherwise null.
    • result an object with the following properties:
      • link the link provided as input
      • status a string set to either alive or dead.
      • statusCode the HTTP status code. Set to 0 if no HTTP status code was returned (e.g. when the server is down).
      • err any connection error that occurred, otherwise null.

Examples

'use strict';

const linkCheck = require('link-check');

linkCheck('http://example.com', function (err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(`${result.link} is ${result.status}`);
});

With basic authentication:

'use strict';

const linkCheck = require('link-check');

linkCheck('http://example.com', { headers: { 'Authorization': 'Basic Zm9vOmJhcg==' } }, function (err, result) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(`${result.link} is ${result.status}`);
});

Testing

npm test

License

See LICENSE.md

link-check's People

Contributors

andreizet avatar cmgrote avatar ehmicky avatar michaelgwelch avatar nicolasmassart avatar pdehaan avatar tcort avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.