title: How to check if a url (or a webservice) is alive in Nodejs?
body: <p>How can we check if a web service or a website is alive in nodejs? I am using node version 6.11 and express. I tried using isAlive in npm, but no luck there. </p>
  
  <p>This is the one I tried, but it return false all the time.</p>
  
  <pre><code>var IsAlive = require('is-alive');
  var isAlive = new IsAlive();
  isAlive.add("http://google.com", 301, function (err) {
      "use strict";
  
      if (err) {
          console.log(err);
      }
  });
  
  setInterval(function () {
      console.log(isAlive.isAlive("http://google.com"));
  }, 2000);
  
  console.log(isAlive.isAlive("http://google.com"));
  </code></pre>
  
  <p>I use using http as well like : </p>
  
  <pre><code>    http.get('http://google.com', function (res) {
  console.log(res);
  
  }).on('error', function(e) {
   console.log(e);
  
  });;
  </code></pre>
  
  <p>And also like : </p>
  
  <pre><code>    var request = require('request');
      options = {method: 'HEAD', host: 'stackoverflow.com', port: 80, path: '/'},
      req = http.request(options, function(r) {
          console.log(JSON.stringify(r.headers));
      });
  req.end();
  </code></pre>
  
  <p>Tried using status code as well  :</p>
  
  <pre><code>var http = require("http");
  http.get({host: "google.com"},function(res){
      if (res.statusCode ==200)
          console.log ("running");
          else 
  console.log ("not running");
  
  
  });
  </code></pre>
  
  <p>Can we use any other method? basically my requirement is to check if a web service which is on a different server.</p>