With Node.js, how can I make two HTTP GET requests and combine the resulting data and send it back to a user? -
say have following code sends json data (that example.com first) user made post request
app.post('/riot', function(request, response) { var riotapi = https.get("https://example.com", function(riotresponse){ var body = ""; riotresponse.on('data', function(chunk){ body+= chunk; }); riotresponse.on('end', function(){ response.type('json'); response.end(body); }); }); });
what do if want more data different website , send json data both website user? using express.
there number of ways can this. suggest using request npm module instead of calling https directly. request
can pass in callback called when request finishes, no need deal chunks of data.
if take approach can use async.parallel() run both requests in parallel. async.parallel
takes 1 callback called when of async functions have finished.. , send response.
Comments
Post a Comment