Simple HTTP status checker w/ timeout
Simple HTTP status checker w/ timeout.
npm install httpcheck
Very simple example to merely check that http://example.com returns a valid HTTP response of some kind:
var check = require'httpcheck'checkurl:""if errconsole.log"HTTP check for example.com failed!"throw errconsole.log"HTTP check for example.com has passed"
Check that http://example.com/404 returns a HTTP response with status code 404 and give it at most 3 tries.
var check = require'httpcheck'checkurl:""checkTries:3if res && resstatusCode === 404return truereturn falseif errconsole.log"HTTP check for example.com failed!"throw errconsole.log"HTTP check for example.com has passed"
httpcheck takes a small number of parameters:
opts is an object with properties:
url: URL to run HTTP check against. Required.
checkTries: Number of times to try the HTTP check. Default is 10.
checkInterval: Interval between HTTP check tries in ms. Default is 1000ms (1 second)
checkTimeout: Timeout for the HTTP check in ms. Default is 30000ms (30 seconds)
check: Custom check function which accepts a HTTP response object and returns
falseon success or failure. Default is that response object is truthy.
log: Custom log function. Default is
cb is a function callback which takes a single parameter indicating error.
httpcheck has tests. Execute
npm test to run them.
httpcheck is released under the BSD license.