Skip to content

Instantly share code, notes, and snippets.

@abcdeepakr
Created February 10, 2022 07:59
Show Gist options
  • Save abcdeepakr/6385243fba11a21bcbd64a8491fb777e to your computer and use it in GitHub Desktop.
Save abcdeepakr/6385243fba11a21bcbd64a8491fb777e to your computer and use it in GitHub Desktop.
Api calls in a for loop
const axios = require('axios')
const fetch = async (id) =>{
let data = await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`).then(res => res.data).catch(err => err.message)
return data
}
const main = async () =>{
for(var i=1;i<10;i++){
let data = await fetch(i)
console.log(data.id)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment