title: Multer req.file.path is undefined
body: <p>Sorry for this simple question. I'm just new to node.js and try to make a RESTapi with express. For file upload I'm using multer from npm. Everything is work fine. But when I try to access multer property in post method by using <em>req.file.path</em> it's throw this message:</p>
  
  <pre><code>{
      "error": {
          "message": "Cannot read property 'path' of undefined"
      }
  }
  </code></pre>
  
  <p>I also try to get other property available in multer like 'mimetype' but same error just property name changed. I'm using <em>postman</em> to send the data.
  Here is my code snippets.</p>
  
  <p><strong><em>product.js</em></strong></p>
  
  <pre><code>import express from 'express';
  import mongoose from 'mongoose';
  import Product from '../models/product.model';
  import multer from 'multer';
  
  const router = express.Router();
  
  const storage = multer.diskStorage({
      destination: (req, file, cb) =&gt; {
          cb(null, './uploads');
      },
      filename: (req, file, cb) =&gt; {
          cb(null, `${new Date().toISOString().replace(/:/g, '-')}${file.originalname}`);
      }
  });
  
  const fileFilter = (req, file, cb) =&gt; {
      // reject a file
      if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
          cb(null, false);
      } else {
          cb(new Error('Only .jpeg or .png files are accepted'), true);   
      }
  };
  
  const upload = multer({
      storage: storage,
      limits: {
          fileSize: 1024 * 1024 * 5
      },
      fileFilter: fileFilter
  });
  
  router.post('/', upload.single('productImage'), (req, res, next) =&gt; {
      const product = new Product({
          _id: new mongoose.Types.ObjectId(),
          name: req.body.name,
          price: req.body.price,
          productImage: req.file.path
      });
      product.save().then(result =&gt; {
          console.log(result);
          res.status(201).json({
              message: 'Created product successfully',
              createdProduct: {
                  name: result.name,
                  price: result.price,
                  _id: result._id,
                  request: {
                      type: 'GET',
                      url: `http://localhost:3000/products/${result._id}`
                  }
              }
          });
      }).catch(err =&gt; {
          console.log(err);
          res.status(500).json({
              error: err
          });
      });
  });
  </code></pre>
  
  <p><strong><em>product.model.ts</em></strong></p>
  
  <pre><code>import mongoose from 'mongoose';
  
  const productSchema = mongoose.Schema({
      _id: mongoose.Schema.Types.ObjectId,
      name: {type: String, required: true},
      price: {type: Number, required: true},
      productImage: { type: String, required: true }
  });
  
  module.exports = mongoose.model('Product', productSchema);
  </code></pre>
  
  <p>I can't find the solution. I've check a couple of solution from stackoverflow but didn't find any solution.</p>