Skip to content

Instantly share code, notes, and snippets.

@Enome
Created March 4, 2013 20:35
Show Gist options
  • Save Enome/5085396 to your computer and use it in GitHub Desktop.
Save Enome/5085396 to your computer and use it in GitHub Desktop.
var http = require('http');
var https = require('https');
var ping = function (domain, callback) {
var protocol = http;
if (domain.url.indexOf('https') === 0) {
protocol = https;
}
var handler = function (start, res) {
callback(null, { url: domain.url, status: res.code || res.statusCode, ms: parseInt(process.hrtime(start)[1] / 10000000, 10) });
}.bind(null, process.hrtime());
var request = protocol.get(domain.url, handler);
request.on('error', handler);
};
module.exports = ping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment