Planning the application
We can split the command-line tool into two parts: the first one reads a directory and returns all the files in it and the second one sends the images to Flickr. It's a good idea to form these two functionalities in different modules. The following diagram shows how our project will appear:
The images
directory will be used as a test folder, that is, our script will do its job in that directory. Of course, we can have another one if we want. The two modules mentioned previously are saved in the lib
directory. So, we should first get the files (Files.js
) and then upload them (Flickr.js
) to the portal. The two operations are asynchronous, so both the modules should accept
callbacks. The following is the content of the index.js
file:
var flickr = require('./lib/Flickr'); var files = require('./lib/Files'); var flickrOptions = {}; files(function(images) { flickr(flickrOptions, images, function() { console.log("All the images uploaded."); process.exit(1); ...