Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created October 17, 2014 07:12
Show Gist options
  • Save JacobHsu/23fbbb54169a7efe78f6 to your computer and use it in GitHub Desktop.
Save JacobHsu/23fbbb54169a7efe78f6 to your computer and use it in GitHub Desktop.
Downloading using wget #nodejs
//note: http://www.html-js.com/article/1961
// Function to download file using wget
var download_file_wget = function(file_url) {
// extract the file name
var file_name = url.parse(file_url).pathname.split('/').pop();
// compose the wget command
var wget = 'wget -P ' + DOWNLOAD_DIR + ' ' + file_url;
// excute wget using child_process' exec function
var child = exec(wget, function(err, stdout, stderr) {
if (err) throw err;
else console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment