Skip to content

Instantly share code, notes, and snippets.

@adamanthil
Created September 10, 2013 23:08
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 adamanthil/6517042 to your computer and use it in GitHub Desktop.
Save adamanthil/6517042 to your computer and use it in GitHub Desktop.
read http response on localhost:3000
var http = require('http');
var options = {
hostname: 'localhost',
port: '3000',
path: '/'
};
callback = function(response) {
var str = '';
// another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
// the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
});
}
var req = http.request(options, callback);
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment