title: Node.js - Promise not resolving within loop
body: <p>Good day all,</p>
  <p>I'm working on extracting some data out of PipeDrive's API using Axios for Node.js. The way that PipeDrive developed their API pagination is a bit different. Here is how their pagination indicator looks:</p>
  <pre><code>    &quot;additional_data&quot;: {
      &quot;pagination&quot;: {
          &quot;start&quot;: 0,
          &quot;limit&quot;: 100,
          &quot;more_items_in_collection&quot;: true,
          &quot;next_start&quot;: 100
      }
  }
  </code></pre>
  <p>I need to interate through all pages to extract the data, and my code has successfully done that, but I cannot get my promise to resolve for some reason.</p>
  <p>My logic in the code is as follows:</p>
  <pre><code>if(more_items_in_collection){Add current page's data then re-run the same function with the next_start as a parameter}
  else{Add current page's data then RESOLVE the promise to complete the function}
  </code></pre>
  <p>But this resolution never happens, even though my code works (strange).</p>
  <p>Gurus, can you please take a look at my code and let me know why you think it won't resolve (<code>function().then((result) =&gt; {OUTPUT})</code> never returns happens)?</p>
  <p>Thanks as always!</p>
  <pre><code> const queryPipeDrive = (start) =&gt;{
   // Query is a full then-able Async function
   return new Promise((resolve, reject) =&gt; {
       // API CALL
       axios({
           method: 'GET', 
           url: pipeDriveURI, 
           params: {
               api_token: apiKey, 
               start: start
           }
       })
       // THEN DO THIS
       .then((response) =&gt; {
           // IF there are more items in collection on additional pages, iterate through the pages
           if(response.data.additional_data.pagination.more_items_in_collection){
               // Add all deals on page to the container
               for (const deal of response.data.data) {
                   db.get('deals').push(deal) // Push deal data to the StormDB File
               }
               
               console.log(chalk.cyan(`${response.data.additional_data.pagination.next_start}`))
               // Function loop created. We will loop UNTIL the 'more_items_in_collection' prop is false, then we'll resolve the promise. 
               queryPipeDrive(response.data.additional_data.pagination.next_start)
  
           }else{
               // Add all deals on this page to the reponse container
               for (const deal of response.data.data) {
                   db.get('deals').push(deal)
               }
               db.save() // Save changes to temp DB
               resolve(response.data.data) // Resolve Promise with the data from the successful call
           }
       })
       .catch((err) =&gt; {
           console.log(chalk.red(err))
           reject(err)
       })
   })
  </code></pre>
  <p>}</p>