I also want to add that the http.ClientResponse
returned by http.get()
has an end
event, so here is another way that I receive the body response:
var options = { host: 'www.google.com', port: 80, path: '/index.html'};http.get(options, function(res) { var body = ''; res.on('data', function(chunk) { body += chunk; }); res.on('end', function() { console.log(body); });}).on('error', function(e) { console.log("Got error: "+ e.message);});