Skip to content

Instantly share code, notes, and snippets.

@niklasfi
Created January 24, 2011 19:26
Show Gist options
  • Save niklasfi/793773 to your computer and use it in GitHub Desktop.
Save niklasfi/793773 to your computer and use it in GitHub Desktop.
This is supposed to be a simple http downloader:
var http = require('http');
var fs = require('fs');
var options = {
host: 'nodejs.org',
port: 80,
path: '/docs/v0.3.6/api/http.html#http.ClientResponse'
};
var ws=fs.createWriteStream('./file');
var cr=http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
})
cr.on('error', function(e) {
console.log("Got error: " + e.message);
});
cr.on('data',function(data) {
ws.write(data);
console.log('got data');
});
cr.on('end', function(){
ws.end();
console.log('server\'s response ended');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment