Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Created April 27, 2020 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manashmandal/d3038773d93afcc113a2fdc4845b1be1 to your computer and use it in GitHub Desktop.
Save manashmandal/d3038773d93afcc113a2fdc4845b1be1 to your computer and use it in GitHub Desktop.
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