We will be working with Promises and the async/await functionality to do some asynchronous programming.
- Create a new directory called
async-implementation
and move into it. - Run
npm init -y
in order to initialize a new node project - Run
npm install axios
in order to install axios as a dependency - Create an
index.js
file. - Require
axios
into theindex.js
file
- Create an
async
function namedfetchPeople
that performs aGET
request using axios tohttps://goodparts.dokku-hosted.thruhere.net/people
using await - Save the data returned from this function call into a variable. (Remember that the actual data returned from an axios request is stored in the data property of the response object). The data you receive will be a group of person objects in an array
- If you have less than 200 elements in the array perform the same operation again, and add all the newly fetched elements to the array. You will need to iterate over the newly retrieved array in order to push the elements into the previously created array.
- Return this array from the
fetchPeople
function and assign it to a variable - Since
fetchPeople
is an async/await function it will always return a promise, write down a promise handler that will iterate over the returned array and will console.log each element inside the array