title: Node js socket explanation
body: <p>I am building an application that will be making about a million calls to a remote api server. Will  I be able to limit amount of connections to for example 10? Do I set max sockets to 10 will do it?</p>
  
  <p>I am trying to understand what do these parameters do:</p>
  
  <pre><code>keepAlive: false,
  maxSockets: 999,
  maxFreeSockets: 1
  </code></pre>
  
  <p>In node http get function, in the following code:</p>
  
  <pre><code>var inputData = [];
  
  for(i=1; i&lt;=5000;i++){
      inputData.push('number' + i);
  }
  
  var options = {
      host: "localhost",
      port: 80,
      path: "/text.txt",
      keepAlive: false,
      maxSockets: 999,
      maxFreeSockets: 1
  }
  
  
  var limit = inputData.length;
  var counter = 0;
  
  function fetchData(number){
  
      return new Promise(function(resolve, reject){
          var http = require('http');
  
          fetch  = function(resp){
              var body = '';
              resp.on('data',function(chunk){
                  body += chunk;
              })
              resp.on('end',function(){
                  console.log(resp)
                  resolve()
              })
              resp.on('error',function(err){
                  console.log('error');
              })
          }
          var req = http.request(options, fetch);
  
          req.end();
  
      })
  }
  
  
  
  Promise.all(inputData.map(number =&gt; fetchData(number))).then(function(results) {
      console.log('finished');
      connection.end();
  
  })
  .catch(function(error) {
      console.log('there wa an error');
      console.log(error);
  });
  </code></pre>