Skip to content

Instantly share code, notes, and snippets.

@bigfleet
Created July 27, 2010 00:09
Show Gist options
  • Select an option

  • Save bigfleet/491490 to your computer and use it in GitHub Desktop.

Select an option

Save bigfleet/491490 to your computer and use it in GitHub Desktop.
var http = require('http');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/',
{'host': 'www.google.com'});
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
➜ node-test git:(master) ✗ node -v
0.1.100
➜ node-test git:(master) ✗ node http-client.js
/Users/bigfleet/node/node-test/http-client.js:6
request.on('response', function (response) {
^
TypeError: Object #<a ClientRequest> has no method 'on'
at Object.<anonymous> (/Users/bigfleet/node/node-test/http-client.js:6:9)
at Module._compile (module:381:21)
at Module._loadScriptSync (module:390:8)
at Module.loadSync (module:296:10)
at Object.runMain (module:444:22)
at node.js:242:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment