title: How to use vanilla Node.js to run 500 requests, 20 in parallel
body: <p>I have this vanilla Node.js code:</p>
  
  <pre><code>const http = require('http');
  
  const host = 'example.com';
  const path = '/';
  
  let i = 0;
  
  const run = () =&gt; {
  
    console.log(i++);
  
    return new Promise(resolve =&gt; {
  
      const req = http.request({host, path}, res =&gt; {
        res.pipe(process.stdout);
        res.once('end', resolve);
      });
  
      req.end();
  
    });
  
  };
  
  async function doall() {
    for (let i = 0; i &lt; 50; i++) {
      await Promise.all(new Array(10).fill(null).map(run));
    }
  }
  
  const now = Date.now();
  
  console.log('Starting up.');
  
  doall().then(_ =&gt; {
    console.log('done after:', Date.now() - now, 'millis');
  });
  
  // the end
  </code></pre>
  
  <p>this works - it runs 50 sets of 10... except the problem is that, all 10 complete, then the next 10 start, then the next 10 complete. So there are moments when 0 requests are in progress, between each set.</p>
  
  <p>Is there some way using vanilla Node.js and promises to replicate <code>async.eachLimit(new Array(500), 20, ...)</code>?</p>