title: How to slow down this Node looping http request?
body: <p>I'm trying to call this API with the <a href="https://www.npmjs.com/package/request" rel="nofollow">request</a> module about 200-300 times with a Lambda function. I need to add second between each call so I don't get a 429 response. I've tried a few different ways to make this happen, but it seems to ignore the code to slow it down.</p>
  
  <p>How do people normally slow down these requests in AWS lambda? It would be great if I could insert something like utilities.sleep(1000) in the loop to make it wait a second before continuing. I'm sure there is a simple solution to this issue, but all the examples I've seen seem to make it complex. </p>
  
  <pre><code>function findProjects(items){
  
      var toggleData = [];
  
      for( var i = 0; i &lt; items.length; i++ ){
          setTimeout( callToggle( items[i] ), 1000 );
      }
  
      function callToggle( data ){
          request({
              'url': 'https://www.toggl.com/api/v8/projects/' + data.toggle.data.id,
              'method': 'GET',
              'headers': {
                  'Content-Type': 'application/json',
                  'Accept': 'application/json'
              },
              'auth': {
                  'user': 'xxxxxxx',
                  'pass': 'api_token'
          }}, function( error, response, body ){
              if( error ) {
  
                  console.log( error );
                  context.done( null, error );
              } else {
  
                  console.log(response.statusCode, "toggle projects were listed");
                  var info = JSON.parse(body);
                  toggleData.push(info);
              }
          });
      }
  
      findDocument( toggleData );   
  }
  </code></pre>