title: Rate limit API requests in node.js
body: <p>First off, I'm new here, so please...be gentle...I've been teaching myself node.js over the last few months, mostly with the desire to scrape a bunch of data from the FlightAware website API.</p>
  
  <p>I am trying to request from their site a list of flights for aircraft, here is what I have so far.  </p>
  
  <pre><code>var aircraft = [array,of,aircraft,tail,numbers]   
  
  for (i=0; i &lt; aircraft.length; i++) {
  
      faGetFlight(aircraft[i],function doneLookup(data) {
  
          dbUpdateFlight(collectionName, data)
      })
  }
  </code></pre>
  
  <p>This code works, but as soon as there is more than 10 aircraft in the list, it fails, because is sending more than 10 API requests in a minute.  What are some easy/straightforward ways to slow this down a little.  I would like to send about 50-60 API requests total each time this runs, so I need it spaced over 5-6 minutes.   The faGetFlight() function uses the 'request' module. I've tried the request-rate-limit module instead of the request module, but I can't seem to make it work. I don't think the authorization works properly with the request-rate-limiter module.  Getting an error about anonymous user. For what it's work, it works with just the request module instead, but I run into the rate limit issues.   </p>
  
  <p>Here is my faGetFlight() code. </p>
  
  <pre><code>var RateLimiter = require('request-rate-limiter');
  const REQS_PER_MIN = 10; // that's 25 per second
  var limiter = new RateLimiter(REQS_PER_MIN);
  
  //API Variables //
  var apiUrl = 'url'
  var apiEndpoint = 'endpoint'
  var apiAuth = 'apikey'
  var apiExtData = 0
  var apiHowMany = 15         //Number of results to request.                                               
  
  var options = { method: 'GET',
      url: apiUrl + apiEndpoint,
      qs: { ident: acIdent
          },
  
          headers: 
      { 
          Authorization: apiAuth }                  
      };
  
          limiter.request(options, function doneDownload(error, response, body) {         
              if (error) throw new error(error);
              callback(body)
          });
  
  }
  </code></pre>
  
  <p>Sorry if this isn't clear...it's my first post!</p>