title: NodeJS: Chain functions automatically in a promise?
body: <p>I'm currently fetching data from an API and I need to do multiple GET requests (using axios). After all those GET requests are completed, I return a resolved promise.</p>
  <p>However, I need to do these GET requests automatically based on an array list:</p>
  <pre class="lang-js prettyprint-override"><code>    function do_api_get_requests() {
  
          return promise = new Promise(function(resolve, reject) {
  
            API_IDs = [0, 1, 2];
  
            axios.get('https://my.api.com/' + API_IDs[0])
            .then(data =&gt; {
              // Do something with data
  
              axios.get('https://my.api.com/' + API_IDs[1])
              .then(data =&gt; {
                // Do something with data
  
                axios.get('https://my.api.com/' + API_IDs[2])
                .then(data =&gt; {
                  // Do something with data
                  
                  // Finished, resolve
                  resolve(&quot;success&quot;);
                  
                }
  
  
              }
  
  
            }
  
          }
  
      }
  </code></pre>
  <p>This works but the problem is API_IDs isn't always going to be the same array, it will change. So I'm not sure how to chain these requests automatically.</p>