title: How to do recursive requests to an API with promise in Node.js?
body: <p>I need to read data from API that only gives 100 results per query and a timestamp from where to get the next 100. </p>
  
  <p>I've managed to do multiple requests one after another with the code below, but for some reason it never returns to the original promise. It gets stuck on the "No more orders to fetch".</p>
  
  <pre><code>app.get('/test', (req, res) =&gt; {
  
    const getOrders = (from) =&gt; {
      return request(mcfApiUrl + "changes?created_after_ts="+from+"&amp;key="+mcfKey)
      .then(xml =&gt; convert.xmlDataToJSON(xml,{explicitArray:false,mergeAttrs:true}))
      .then(orders =&gt; checkForMore(orders));
    }
  
    const checkForMore = (orders) =&gt; {
      return new Promise((resolve, reject) =&gt; {
        if (orders['Orders']['orders'] == 100){
          getOrders(orders['Orders']['time_to']);
          console.log("Fetched "+ orders['Orders']['orders']+" orders");
          console.log("More orders available from: "+moment(orders['Orders']['time_to']*1000).format());
        }
        else {
          console.log("Fetched "+ orders['Orders']['orders']+" orders");
          console.log("No more orders to fetch");
          resolve(orders);
        }
      });
    };
  
    var fromdate = 1483999200;
  
    getOrders(fromdate)
    .then(output =&gt; res.send("Done")) // It never gets here
    .catch(err =&gt; console.log(err));
  
  });
  </code></pre>
  
  <p>What am I missing?</p>