title: express.js multiple file upload callback
body: <p>I'm new to node.js &amp; express.js, so... I want to upload multiple files, and later work with them.
  But i need to send a response (ok or error status) after all my files have been saved on disk, or if one failed - then send an error callback.</p>
  
  <p>Now I have such code:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  var multipart = require('connect-multiparty');
  var multipartMiddleware = multipart();
  
  var fs = require('fs');
  
  router.post('/upload', multipartMiddleware, function(req, res) {
    var reqBody = req.body;
    var reqFiles = req.files;
  
    saveFile(reqFiles, 'main.xlsx', function(err) {
      if (err) {
        res.status(404).send('');
        return;
      }
  
      res.send('Multi-File File uploaded');
    }
  });
  
  function saveFile(file, name, callback) {
    fs.writeFile('./uploads/' + name, file, callback);
  }
  </code></pre>
  
  <p>but how can i change my code to parse this:</p>
  
  <pre><code>router.post('/upload', multipartMiddleware, function(req, res) {
    var reqBody = req.body;
    var reqFiles = req.files;
  
    saveFile(reqFiles['files'][0], 'main.xlsx', function(err) {
      if (err) {
        res.status(404).send('');
        return;
      }
    }
    saveFile(reqFiles['files'][1], 'second.xlsx', function(err) {
      if (err) {
        res.status(404).send('');
        return;
      }
    }
  
    res.send(''); // only after first two fileUploaders have finished
  });
  
  function saveFile(file, name, callback) {
    fs.writeFile('./uploads/' + name, file, callback);
  }
  </code></pre>