Created
January 24, 2011 19:26
-
-
Save niklasfi/793773 to your computer and use it in GitHub Desktop.
This is supposed to be a simple http downloader:
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 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