Created
September 10, 2013 23:08
-
-
Save adamanthil/6517042 to your computer and use it in GitHub Desktop.
read http response on localhost:3000
This file contains 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 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