Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created October 14, 2016 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrinek/99cfdd8d8d48837fd2fd7db6602f2fd3 to your computer and use it in GitHub Desktop.
Save vrinek/99cfdd8d8d48837fd2fd7db6602f2fd3 to your computer and use it in GitHub Desktop.
var http = require('http');
var countdown = 10;
function makeRequest(iteration) {
var t = Date.now();
http.request({
host: 'www.google.com',
path: '/'
}, function(response){
var str = '';
response.on('error', function(err){
console.error(err);
});
response.on('data', function(chunk){
str += chunk;
});
response.on('end', function(){
console.log(response.statusCode, str.length, Date.now() - t);
});
}).end(function(){
iteration++;
if(iteration <= countdown) {
setTimeout(function(){
makeRequest(iteration);
}, 500);
}
});
}
makeRequest(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment