Skip to content

Instantly share code, notes, and snippets.

@fernandezpablo85
Created January 16, 2012 23:59
Show Gist options
  • Select an option

  • Save fernandezpablo85/1623715 to your computer and use it in GitHub Desktop.

Select an option

Save fernandezpablo85/1623715 to your computer and use it in GitHub Desktop.
A simple http client written in node.js
var options = {
host: 'www.example.com',
port: 80
};
var request = http.request(options, function (response) {
// print status code
console.log('status-code:', response.statusCode);
// print data as it arrives (streaming)
response.on('data', function (chunk) {
console.log('chunk:', chunk);
});
// wave goodbye when the request ends.
response.on('end', function () {
console.log('see you!');
});
});
// handle errors
request.on('error', function (err) {
console.error('oh snap!', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment