Created
April 27, 2020 11:54
-
-
Save manashmandal/d3038773d93afcc113a2fdc4845b1be1 to your computer and use it in GitHub Desktop.
Concurrent Requests Using NodeJs
This file contains hidden or 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 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)); | |
})(); |
This file contains hidden or 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
{ | |
"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