I have simple nodejs function that should work as follow:
- Making GET request to list of urls.
- Collecting all responses to array.
- Print responses line by line.
Problem is that I initialize results array at start and in middle of function I am pushing response strings to this array, but at the end this array is empty.
var http = require('http');
var bl = require('bl');
var argv = process.argv;
var results = [];
for (i = 2; i < argv.length; i++) {
var url = argv[i].toString();
http.get(url, function (response) {
response.pipe(bl(function (err, data) {
results.push(data.toString()); //if im just printing the data it shows the correct info.
}))
})
}
console.log(results);
So response is just "[]".