Created
January 16, 2012 23:59
-
-
Save fernandezpablo85/1623715 to your computer and use it in GitHub Desktop.
A simple http client written in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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