Check if a server is running. Is both a module and an executable.
Will report an error if there is the statuscode is 4xx, 5xx or if the server doesn't respond.
npm install -g http-monitor
With the commandline tool you can set up commands that will be executed when the status of the server changes:
The commands will only be called once if the state of the server changes. Like this scenario:
The server is running perfectly for 3 days, but now stops replying. This will cause the on-connection-error to be executed once. After 30 minutes the server starts to reply again, and then the on-recovery command is executed once.
http-monitor--on-http-error "command..." # When there is a 4xx or 5xx response code--on-connection-error "command..." # When there is a connection errror (no reply) from the server--on-error "command..." # When either a connection/http error occur--on-recovery "command..." # When the server recovers after a period with errors--interval 5min # How often to check--retries 4 # How many times to retry--allow 501 # Allow a 4xx or 5xx code which would otherwise cause an error--disallow 301 # Disallow a 1xx, 2xx, or 3xx code which wouldn't otherwise cause an error--once # Only run once, then call callback and exit
"command..." part is a command you want executed when an error occurs. You can use
%body in this. e.g.
--on-http-error "call 1234567890 Hi Bill. Server crashed, %url. Returned %statuscode and %body".
var monitor = ;;
monitor function returns a stop-function. Call this to stop the monitor.
var monitor = ;var localhost =;;
How many miliseconds to wait between the checks. Default is
How many tries in a row that should fail before it will call the callback with an error. Default is
How many miliseconds should each request maximum take before it is seen as an error. Default is
As default http-monitor will call the callback with an error if the server returned a 4xx or 5xx status code. This allows http-monitor to allow certain error codes.
[501, 502] would allow the server to return 501 and 502. Default is
As default http-monitor will call the callback without an error if the server returned a 1xx, 2xx, or 3xx status code. Use this to disallow certain error codes and call the callback with an error.
[301, 307] would disallow the server to return 301 and 307. Default is
Normally http-monitor will keep pinging the server at the url, but if you set once to true, then it will only happen once and after the callback has been called the first time, it will stop. Default is