title: Nodejs function to check if website is working
body: <p>I'm trying to make a function that checks if the given URL is working or not.
  This is what I've done so far:</p>
  
  <pre><code>function checkWebsite(url) {
    http
      .get(url, function(res) {
        console.log(url, res.statusCode);
        return res.statusCode === 200;
      })
      .on("error", function(e) {
        return false;
      });
  }
  </code></pre>
  
  <p>I want to wait until http get is finished and then return true or false based on the status code and being the response in a callback function I don't know how to return it back to where it was called.
  Example call:</p>
  
  <pre><code>function test() {
     if (checkWebsite("https://stackoverflow.com/")) {
      return "https://stackoverflow.com/";
     } 
  }
  </code></pre>
  
  <p>I want to get the true or false in this if statement but since the status code is in a callback function I don't know how to return it.</p>