title: Node.JS ping server with IP and Directory
body: <p>I have been struggling to find a way to use node.js to check the response of a server ip that has directory's after it. I can ping a server just with a port but thats not what is required.</p>
  
  <p><strong>The URL</strong></p>
  
  <blockquote>
    <p>127.0.0.1:9191/api/WebApis</p>
  </blockquote>
  
  <p><strong>My code so far</strong></p>
  
  <pre><code>var net = require('net');
  var hosts = [['127.0.0.1:9191/api/WebApis', 9191]];
  
  setInterval(function(){
      hosts.forEach(function(item) {
          var sock = new net.Socket();
          sock.setTimeout(2500);
          sock.on('connect', function() {
              console.log(item[0]+':'+item[1]+' is up.');
              sock.destroy();
          }).on('error', function(e) {
              console.log(item[0]+':'+item[1]+' is down: ' + e.message);
          }).on('timeout', function(e) {
              console.log(item[0]+':'+item[1]+' is down: timeout');
          }).connect(item[1], item[0]);
      });
  }, 1000);
  </code></pre>
  
  <p><strong>Node JS Output</strong></p>
  
  <blockquote>
    <p>127.0.0.1:9191/api/WebApis:9191 is down: getaddrinfo ENOTFOUND 127.0.0.1:9191/api/WebApis127.0.0.1:9191/api/WebApis:9191</p>
  </blockquote>