Created
February 10, 2022 07:59
-
-
Save abcdeepakr/6385243fba11a21bcbd64a8491fb777e to your computer and use it in GitHub Desktop.
Api calls in a for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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