Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if website is contactable

I want to check if a specific website is online. The name of the website comes from an input field and is sending via post.

There is an NPM module for ping hosts, but this do not help me so much. I need a solution for checking URL's with params, like: hostname.com/category

I would be grateful for suggestions.

like image 459
pkberlin Avatar asked Dec 06 '14 15:12

pkberlin


1 Answers

Just make an HTTP request.

var http = require('http');
http.get('http://example.com/category', function (res) {
  // If you get here, you have a response.
  // If you want, you can check the status code here to verify that it's `200` or some other `2xx`.

}).on('error', function(e) {
  // Here, an error occurred.  Check `e` for the error.

});
like image 85
Brad Avatar answered Oct 14 '22 15:10

Brad