In modern computers, moving a directory with 500K files is nothing. When you fs.readdir asynchronously in Node.js, what it does is just read the list of file names in the specified directory. It does not read the contents of files. I just tested 700K files in a directory. Only 21 MB of memory is required to download this list of file names.
Once you have downloaded this list of file names, you simply go through them one at a time or in parallel, setting a limit for concurrency, and you can easily use them. Example:
var async = require('async'), fs = require('fs'), path = require('path'), parentDir = '/home/user'; async.waterfall([ function (cb) { fs.readdir(parentDir, cb); }, function (files, cb) {
source share