title: Call back after all the files are uploaded in express js using busboy
body: <p>I have an Express application with multiple upload. I'm using busboy for accessing the multipart. I have to send the files to an external API server. Currently I am uploading all the files to a directory using <code>fs.createWriteStream()</code> and then after reading the files using <code>fs.createReadStream</code>, sending the files to the external API server. How can I get a callback function after uploading all the files and reading all the files? Or else can I send the files directly to the external server without saving it in the express server? Here is my code,</p>
  
  <pre><code>exports.create(req, res, next) =&gt; {
      req.pipe(req.busboy);
      let fileCount = 0;
      let filesToSent = [];
      req.busboy.on('file', (fieldname, file, filename, encoding, mimetype) =&gt; {
          let fileNameArray = filename.split('.'),
              fileExtension = fileNameArray[fileNameArray.length - 1],
              d = new Date(),
              fileNameToSave = d.getFullYear().toString() + (d.getMonth() + 1).toString() + d.getDate().toString() + d.getTime().toString() + '_' + fileCount + '.' + fileExtension;
          fileCount += 1;
          let fileUpload = file.pipe(fs.createWriteStream('./app/tempupload/' + fileNameToSave));
          fileUpload.on('finish', () =&gt; {
              let uploadedFile = fs.createReadStream('./app/tempupload/' + fileNameToSave);
              uploadedFile.on('finish', () =&gt; {
                  filesToSent.push(uploadedFile);
                  console.log(filesToSent);
              });
          });
      });
  }
  </code></pre>