I need to make thumbnails of images in about 1000 directories. I'm using the library imagemagick.
async.each(files, function(file, cb) { if (fs.existsSync(process.env.UPLOAD_BASE_PATH + file + '/P.png')) { im.resize({ srcPath: process.env.UPLOAD_BASE_PATH + file + '/P.png', dstPath: process.env.UPLOAD_BASE_PATH + file + '/thumb.png', width: 225 }, function (err, stdout, stderr) { setTimeout(function () { console.log('File rezied: ' + process.env.UPLOAD_BASE_PATH + file + '/thumb.png'); cb(); //Done resizing image }, 100) }); } else { cb(); } }, function(err){ if (err){ console.log(err); res.send(400); } res.send(200); //All files resized }); It works but after a few hundred images I get: Error: spawn EAGAIN. It got something to do with number of processes running. Anything I can do about it? Most preferably in my node code.