Skip to content

Instantly share code, notes, and snippets.

@andrijac
Created June 1, 2014 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrijac/5d7278e3207d2a17ed11 to your computer and use it in GitHub Desktop.
Save andrijac/5d7278e3207d2a17ed11 to your computer and use it in GitHub Desktop.
Download file using node.js, proxy is included.
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