pkberlin
pkberlin

Reputation: 852

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.

Upvotes: 8

Views: 9187

Answers (1)

Brad
Brad

Reputation: 163272

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.

});

Upvotes: 12

Related Questions