title: Resolve n from promise and create n promises - how do I do this without nesting promises?
body: <p>I'm working in node and must make n amount of API calls after getting n returned from a promise. My initial thought would be to create a foreach loop that creates n promises, store them in an array, and then call </p>
  
  <p><code>Promise.all(promisesArray).then(function(){...});</code> </p>
  
  <p>However, this would have the be wrapped in the <code>then()</code> call from the original promise, effectively setting up a nested promise situation. </p>
  
  <pre><code>getN() //returns a promise object.
  .then(function(n) {
      var promisesArray = [];
      for(var i = 0, i &lt; n; i++) {
          var promise = new Promise(function(resolve, reject) { callSomething(i, resolve) });
          promisesArray.push(promise);
  
      }
      Promises.all(promisesArray).then(function(){
          ... 
          resolve; //resolves original promise
      });
  .then(function(something) {...})
  .catch(function(err) {...};
  </code></pre>
  
  <p>How can I avoid this? Thanks for your help!</p>