Last active
December 19, 2015 05:29
-
-
Save rosschapman/5904686 to your computer and use it in GitHub Desktop.
download-things-with-node.js
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 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