Created
June 1, 2014 13:27
-
-
Save andrijac/5d7278e3207d2a17ed11 to your computer and use it in GitHub Desktop.
Download file using node.js, proxy is included.
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 readline = require('readline'); | |
var path = require('path'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
if (process.argv.length < 3) { | |
console.log('invalid number of parameters'); | |
process.exit(0); | |
} | |
var downloadUrl = process.argv[2]; | |
console.log(downloadUrl); | |
var fileName = path.basename(downloadUrl); | |
var fullPath = path.resolve(__dirname, fileName); | |
var file = fs.createWriteStream(fullPath); | |
var options = { | |
host: "xxx", | |
port: 8080, | |
path: downloadUrl | |
}; | |
var request = http.get(options, function(response) { | |
response.pipe(file); | |
}).on('error', function(err) { // Handle errors | |
//fs.unlink(dest); // Delete the file async. (But we don't check the result) | |
console.log(err.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment