Skip to content

Instantly share code, notes, and snippets.

@rosschapman
Last active December 19, 2015 05:29
Show Gist options
  • Save rosschapman/5904686 to your computer and use it in GitHub Desktop.
Save rosschapman/5904686 to your computer and use it in GitHub Desktop.
download-things-with-node.js
var fs = require('fs');
var mkdirp = require('mkdirp');
var request = require('request');
localPathToThing = '/path/to/things';
arrayOfUrls = ['http://all-the-things.com/thing-1.png','http://all-the-things.com/thing-2.png','http://all-the-things.com/thing-3.png', ...]
arrayOfUrls.forEach(function(url,index){
var dirFrag = url.replace( url.substr( url.lastIndexOf('/') + 1 ), '' );
if( !fs.existsSync(__dirname + localPathToThing + dirFrag ) ) {
mkdirp(__dirname + localPathToThing + dirFrag, function (err) {
if (err) throw err;
request('http://remote-url/' + url).pipe(fs.createWriteStream(__dirname + localPathToThing + url));
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment