Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

check-url

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-url

Check a remote URL's HTTP response.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

check-url

Check a remote URL's HTTP response.

Why?

Because you want a poorly written link checker.

Installation:

$ npm i check-url -S

API:

function checkUrl(url, method='HEAD', data={}) {...}

Usage:

const { checkUrl } = require('check-url');

checkUrl('http://latimes.com')
  .then((res) => console.log(res))
  .catch((err) => console.error(err.message));

Output:

{ "contentType": "text/html;charset=UTF-8",
  "ok": true,
  "origUrl": "http://latimes.com",
  "status": 200,
  "statusText": "OK",
  "url": "http://www.latimes.com/" }

In some cases, a server may not respond to a method=HEAD request, so you can override the request method by passing the optional second parameter, method, as seen in the following example:

const { checkUrl } = require('./index');

checkUrl('https://www.wellsfargo.com', 'HEAD', {__method: 'HEAD'})
  .then((res) => console.log(res))
  .catch((err) => console.error(err.message));

/* OUTPUT:
{ __method: 'HEAD',
  contentType: 'text/html;charset=UTF-8',
  ok: false,
  origUrl: 'https://www.wellsfargo.com',
  status: 400,
  statusText: 'Bad request',
  url: 'https://www.wellsfargo.com' }
*/


checkUrl('https://www.wellsfargo.com', 'GET', {__method: 'GET'})
  .then((res) => console.log(res))
  .catch((err) => console.error(err.message));

/* OUTPUT
{ __method: 'GET',
  contentType: 'text/html;charset=UTF-8',
  ok: true,
  origUrl: 'https://www.wellsfargo.com',
  status: 200,
  statusText: 'OK',
  url: 'https://www.wellsfargo.com' }
*/

Similarly, if you want the promise to pass you back some data, you can pass an optional third parameter, data, which will be merged into the response:

const { checkUrl } = require('./index');

checkUrl('http://latimes.com', 'HEAD', {_id: '__LATIMES'})
  .then((res) => console.log(res))
  .catch((err) => console.error(err.message));

/* OUTPUT:
{ _id: '__LATIMES',
  contentType: 'text/html;charset=UTF-8',
  ok: true,
  origUrl: 'http://latimes.com',
  status: 200,
  statusText: 'OK',
  url: 'http://www.latimes.com/' }
*/

Or, if you're trying to process obscenely large lists of URLs, you may need to throttle yourself, before you wreck yourself:

const { checkUrl } = require('check-url');

const Queue = require('promise-queue');
const tippyTopSites = require('tippy-top-sites');

const queue = new Queue(10);

tippyTopSites.forEach(({url}) => queue.add(() => {
  return checkUrl(url)
    .then((res) => console.log(res))
    .then(() => {
      if (queue.getQueueLength() === 0) {
        console.log('queue empty...');
        process.exit(0);
      }
    });
}));

FAQs

Package last updated on 06 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc