Hello I'm new to NodeJs and am trying to work out the best way to get this chain of events working. I have to do two API calls get all the information I need. The first API call is just a list of IDs, then the second API call I pass the ID to get the rest of the information for each object. 

However using the method below, I have no idea when everything is finished. Please can someone help me out.

```
   function getData() { 
            var options = {
            method: 'GET',
            uri: 'https://api.call1.com',
                qs: {
                    access_token: _accessToken,
                }
            };
            request(options).then(function(apires){
               console.log("complete 1");
                var obj = JSON.parse(apires);
                obj.data.forEach(function(entry) {        
                    findMore(entry.id)
                });
            })
   }

   function findMore(id) {
            var options = {
            method: 'GET',
            uri: 'https://api.call2.com',
                qs: {
                    access_token: _accessToken,
                }
            };
            request(options).then(function(apires){
               console.log("complete 2");
                var obj = JSON.parse(apires);
            })
   }

```
['https://Stackoverflow.com/questions/45825412', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4071548/']
You can make your findMore method return a promise, so you can pass an array of those to Promise.all and handle the .then when all promises have finished.

```
function getData() { 
        var options = {
        method: 'GET',
        uri: 'https://api.call1.com',
            qs: {
                access_token: _accessToken,
            }
        };

        request(options).then(function(apires){
           console.log("complete 1");
            var obj = JSON.parse(apires);
            var promises = [];

            obj.data.forEach(function(entry) {        
                promises.push(findMore(entry.id));
            });

            return Promise.all(promises);
        })
        .then(function (response) {
             // Here response is an array with all the responses
             // from your calls to findMore
         })
 }

 function findMore(id) {
        var options = {
        method: 'GET',
        uri: 'https://api.call2.com',
            qs: {
                access_token: _accessToken,
            }
        };
        return request(options);
 }

```
You want to use Promise.all. 

So first thing first, you need an array of promises. Inside your for each loop, set findMore to a variable, and make it return the promise. Then have a line where you do Promise.all(promiseArr).then(function(){console.log("done)})

Your code would look like this

```
function getData() { 
            var promiseArr = []
            var options = {
            method: 'GET',
            uri: 'https://api.call1.com',
                qs: {
                    access_token: _accessToken,
                }
            };
            request(options).then(function(apires){
               console.log("complete 1");
                var obj = JSON.parse(apires);
                obj.data.forEach(function(entry) {        
                    var p = findMore(entry.id)
                    promiseArr.push(p)
                });
            }).then(function(){
                       Promise.all(promiseArr).then(function(){
                       console.log("this is all done")
                       })
                    })
   }

   function findMore(id) {
            var options = {
            method: 'GET',
            uri: 'https://api.call2.com',
                qs: {
                    access_token: _accessToken,
                }
            };
            return request(options).then(function(apires){
               console.log("complete 2");
                var obj = JSON.parse(apires);
            })
   }

```

the basic idea of Promise.all is that it only executes once all promises in the array have been resolved, or when any of the promises fail. You can read more about it [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)