Skip to content

ralphtheninja/test-http-get

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-http-get

Test if a http request succeedes or not.

npm Node version Build Status JavaScript Style Guide

Use when you want to test if a resource exists and don't really care about the actual content of the resource. Will follow redirect responses.

Install

$ npm i test-http-get -S

Usage

Test if rvagg/node-levelup exists (GitHub should redirect to level/levelup):

const test = require('test-http-get')
test('https://github.com/rvagg/node-levelup', (err, exists) => {
  console.log(exists) // --> true
})

API

const test = require('test-http-get')

Returns a single function, see below.

test(url, cb)

Makes a http HEAD request on url.

  • If the status code is a redirect response, the request will be made again based on the returned Location header. Chainable redirect responses are handled up until a limit of 5 steps.
  • Calls back with cb(null, true) if the status code is < 300.
  • Calls back with cb(null, false) for status codes >= 400.
  • Calls back with cb(err) if no request could be made. Most likely an issue with the network or too many total redirect attempts.

License

MIT

About

Test if a http request succeedes or not.

Resources

Stars

Watchers

Forks

Packages

No packages published