Created
April 19, 2012 08:50
-
-
Save francois2metz/2419820 to your computer and use it in GitHub Desktop.
Download and write to file with node
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
#!/usr/bin/env node | |
// modify here | |
var downloadURL = "http://nodejs.org/dist/v0.6.15/node-v0.6.15.tar.gz" | |
var dest = "/tmp/result" | |
// require | |
var http = require('http') | |
var url = require('url') | |
var fs = require('fs') | |
// ugly code here | |
var urlParsed = url.parse(downloadURL) | |
var file = fs.createWriteStream(dest) | |
http.get({host: urlParsed.hostname, | |
path: urlParsed.path}, function(res) { | |
res.pipe(file) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment