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 need to use `Promise.all` to run all async requests in parallel. Also you *must* return the result of `findMore` and `getData` (they are promises). 

```
function getData() { 
  var options = {...};
  return request(options)
    .then(function(apires) {
      console.log("complete 1");
      var obj = JSON.parse(apires);
      var ops = obj.data.map(function(entry) {
        return findMore(entry.id);
      });
      return Promise.all(ops);
}

function findMore(id) {
  var options = {...};
  return request(options)
    .then(function(apires) {
      console.log("complete 2");
      return JSON.parse(apires);
    });
}

getData()
  .then(data => console.log(data))
  .catch(err => console.log(err));

```

If you can use ES7, it can be written with async/await:

```
let getData = async () => { 
  let options = {...};
  let res = awit request(options);
  let ops = res.data.map(entry => findMore(entry.id));
  let data = await Promise.all(ops);
  return data;
};

let findMore = async (id) => {
  let options = {...};
  let apires = awit request(options);
  return JSON.parse(apires);
};

```