I'd like to do something along the lines of:
Promise.all([
fetch(url1).then(function(response){ return response.json() }),
fetch(url2).then(function(response){ return response.json() }),
fetch(url3).then(function(response){ return response.json() }),
fetch(url4).then(function(response){ return response.json() })
]).then(allResponses => {
var data1 = allResponses[0];
var data2 = allResponses[1];
var data3 = allResponses[2];
var data4 = allResponses[3];
// process data....
});
The above is React.js code, I'd like to do the same thing but with Node.js on the server. Problem is I don't have fetch, I have request (should I even be using Request?). https://github.com/request/request It's used in this way...
var request = require('request');
request(url1, function (error, response, body) {
});
But how would I use request with Promise.all? Because I want to fetch multiple things and only process them when all are done but in Node, and I'd rather not use a bunch of callbacks.