Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Concurrent Requests Using NodeJs
const axios = require("axios");
const endpoint = "https://randomuser.me/api";
const totalRequests = 20;
(async () => {
let requests = [];
for (let i = 0; i < totalRequests; i++) {
requests.push(axios.get(endpoint));
}
Promise.all(requests)
.then((responses) => {
responses.map((r) => console.log(r.data));
})
.catch((e) => console.error(e));
})();
{
"name": "concurrent",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment