I am trying to push the result obtained from a URL using http into an array. Following is the code:
var bl = require('bl')
var http = require('http')
var contents = []
var urls = process.argv.slice(2)
urls.forEach((url) => {
http.get(url, (res) => {
res.setEncoding('utf-8')
res.pipe(bl((err, data) => {
if(err)
return console.error(err)
else
contents.push(data.toString())
}))
})
})
contents.forEach( (con) => {
console.log(con)
})
But for some reason I get an empty 'contents' array. Any help?