UNPKG

learnyounode

Version:

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.

33 lines (27 loc) 555 B
'use strict' const http = require('http') const bl = require('bl') const results = [] let count = 0 function printResults () { for (let i = 0; i < 3; i++) { console.log(results[i]) } } function httpGet (index) { http.get(process.argv[2 + index], function (response) { response.pipe(bl(function (err, data) { if (err) { return console.error(err) } results[index] = data.toString() count++ if (count === 3) { printResults() } })) }) } for (let i = 0; i < 3; i++) { httpGet(i) }