I am trying to call multiple URL in a single URL call and push it's json response in an array and send that array in response to the end user.
My code look like this:
var express = require('express');
var main_router = express.Router();
var http = require('http');
urls = [
"http://localhost:3010/alm/build_tool",
"http://localhost:3010/alm/development_tool",
"http://localhost:3010/alm/project_architecture"];
var responses = [];
main_router.route('/')
.get(function (req, res) {
var completed_requests = 0;
for (url in urls) {
http.get(url, function(res) {
responses.push(res.body);
completed_request++;
if (completed_request == urls.length) {
// All download done, process responses array
}
});
}
res.send(responses);
});
I have also tried this using npm request module. When i run this code it only return NULL or some random output that have only headers.
My aim is to call multiple URL's in a single node get request and append it's JSON output on a array and send to the end user.
Thanks
res.on('end', function...