title: File uploading with Express 4.0: req.files undefined
body: <p>I'm attempting to get a simple file upload mechanism working with Express 4.0 but I keep getting <code>undefined</code> for <code>req.files</code> in the <code>app.post</code> body. Here is the relevant code: </p>
  
  <pre><code>var bodyParser = require('body-parser');
  var methodOverride = require('method-override');
  //...
  app.use(bodyParser({ uploadDir: path.join(__dirname, 'files'), keepExtensions: true })); 
  app.use(methodOverride()); 
  //...
  app.post('/fileupload', function (req, res) {
    console.log(req.files); 
    res.send('ok'); 
  }); 
  </code></pre>
  
  <p>.. and the accompanying Pug code: </p>
  
  <pre><code>form(name="uploader", action="/fileupload", method="post", enctype="multipart/form-data")
      input(type="file", name="file", id="file")
      input(type="submit", value="Upload")
  </code></pre>
  
  <p><strong>Solution</strong><br>
  Thanks to the response by <a href="https://stackoverflow.com/users/2050455/mscdex">mscdex</a> below, I've switched to using <code>busboy</code> instead of <code>bodyParser</code>:</p>
  
  <pre><code>var fs = require('fs');
  var busboy = require('connect-busboy');
  //...
  app.use(busboy()); 
  //...
  app.post('/fileupload', function(req, res) {
      var fstream;
      req.pipe(req.busboy);
      req.busboy.on('file', function (fieldname, file, filename) {
          console.log("Uploading: " + filename); 
          fstream = fs.createWriteStream(__dirname + '/files/' + filename);
          file.pipe(fstream);
          fstream.on('close', function () {
              res.redirect('back');
          });
      });
  });
  </code></pre>