npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

is-link-working

v2.2.0

Published

Checks if a given link is working or broken

Downloads

434

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).

Tries a HEAD request first because it's faster. If that fails, tries a GET request and aborts it as soon as we got the response headers. If the URL is unreachable, optionally 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 false)
  • 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.