title: multer - req.file is undefined.
body: <p>I am creating an app using Node, Express and Handlebars and multer for uploading images. Every time I submit the form, req.file is undefined. I've spent the entire day troubleshooting but can't figure out what I'm doing wrong.   </p>
  
  <p><strong>Router File:</strong> </p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const multer = require('multer');
  const mongoose = require('mongoose');
  const path = require('path');
  const methodOverride = require('method-override');
  
  
  //Set Storage Engine
  const storage = multer.diskStorage({
      destination: './public/uploads/images',
      filename: function (req, file, cb) {
          cb(null, file.fieldname + '-' + Date.now() + 
      path.extname(file.originalname));
      }
  });
  
  const upload = multer({
      storage: storage
  }).single('featuredImage');
  
  //Change Featured Image - POST
  router.post('/saveImage/:id', (req, res) =&gt; {
      console.log(req.file);
  
      //removed the rest of the code to keep it simple. req.file here is always undefined.
  
  });
  </code></pre>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;form action="/saveImage/{{pitch.id}}" method="POST" enctype="multipart/form-data"&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="featuredImage"&gt;Featured Image&lt;/label&gt;
           &lt;input type="file" name="featuredImage" id="featuredImage"&gt;
       &lt;/div&gt;
  
       &lt;input type="submit" value="SAVE"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>app.js</strong> these requires are in the app.js file. </p>
  
  <pre><code>const express = require('express');
  const exphbs  = require('express-handlebars');
  const path = require('path');
  const passport = require('passport');
  const mongoose = require('mongoose'); 
  const bodyParser = require('body-parser');
  const flash = require('connect-flash');
  const session = require('express-session');
  const methodOverride = require('method-override');
  const nodemailer = require('nodemailer');
  
  //Set StaticFolder
  app.use(express.static(path.join(__dirname, 'public')));
  </code></pre>