title: Node.js request - handling multiple POST requests
body: <p>I use request library to communicate with other servers via API. But now I need to send multiple (10 or more) POST requests at the same time and move further only if all responsens will be correct. Usually syntax looks a bit like this: </p>
  
  <pre><code>var options = {
  url: "",
  method: "POST",
  header: {...},
  body: {...}
  };
  
  request(options, function(err,response,body)
  {
  }
  </code></pre>
  
  <p>But now I've got an array of objects instead of a single options variable. Is there a way to do this? Or maybe there is another library able to handle the issue.</p>
  
  <p>EDIT:</p>
  
  <pre><code>var arrayOfIds = [];
  const requests = [];
  for(var i in range){
     var options = {} // here goes all bodies and headers to send
     requests.push( // push a request to array dynamically 
      request(options, function(err,response,body){
       if(!err &amp;&amp; response.statusCode == 201){
        arrayOfIds.push(body.id);
       }
     }));
  
  Promise.all(requests)
  .then(function(res){
      console.log(arrayOfIds); // this is empty
  });
  </code></pre>