I'd like to know how to execute async functions, my goal is to uploads files and compress them... But it doesn't work because my files are not yet uploading when I write the .zip...
SO I get an empty .zip file...
var asyncTasks = []; selectedPhotos.forEach(function(id){ asyncTasks.push(function(callback){ var newFileName = pathDir + '/' + id + '.jpg'; api.media(id, function(err, media, remaining, limit) { gm() .in('-page', '+0+0') .in('./public/images/instabox.jpg') .in('-page', '+10+10') .in(media.images.thumbnail.url) .mosaic() .minify() .write(newFileName, function (err) { if (!err) console.log('done'); if (err) console.log(err); }); }); callback(); }); }); async.parallel(asyncTasks, function(){ var admZip = new AdmZip(); var pathDir = './public/uploads/'+reference; admZip.addLocalFolder(pathDir); var willSendthis = admZip.toBuffer(); admZip.writeZip('./public/uploads/'+reference+'.zip'); });