Test if a http request succeedes or not.
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.
$ npm i test-http-get -S
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
})
Returns a single function, see below.
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.
MIT