title: why am i not getting post api body inside multer request body in node.js?
body: <p>I have a <code>node.js</code> based server in which i have <code>addProduct</code> api in which i am receiving an object and image files also. </p>
  
  <p>in my <code>api.route.js</code> file i am doing like this</p>
  
  <pre><code>import { Router } from "express";
  import { log, loggedIn } from "./middlewares/index";
  import { addProduct, getAllProducts, getProductById, updateProduct, deleteProduct } from "./handlers/product";
  const multer = require('multer');
  const uploadFolder = 'uploads/';
  const fs = require('fs');
  
  
  var storage = multer.diskStorage({
  destination: (req, file, cb) =&gt; {
      // console.log(req.res, 'name')
      // console.log(Object.keys(req), 'keys')
      if (fs.existsSync(`uploads/${req.body.categoryName}`)) {
          cb(null, `uploads/${req.body.categoryName}`);
      } else {
          fs.mkdir(`uploads/${req.body.categoryName}`, err =&gt; {
              if (err) {
                  console.log('err in creating folder', err);
              } else {
                  cb(null, `uploads/${req.body.categoryName}`);
              }
           });
         }
       },
        filename: (req, file, cb) =&gt; {
         cb(null, file.originalname);
        }
       });
  
    var upload = multer({
       storage: storage
    })
  
  router.post("/", log, upload.fields([{ name: 'image' }, { name: 'cover_image' }, { name: 'thumbnail_image' }]), addProduct);
  </code></pre>
  
  <p>And in my <code>product.controller.js</code> i am doing like this</p>
  
  <pre><code>export async function addProduct(req, res) {
  let productImages = [];
  try {
      let body = parseBody(req)
          // console.log('----body----', body)
      if (body) {
          console.log(req.files, 'files')
          if (req.files['image']) {
              req.files['image'].forEach(item =&gt; {
                  productImages.push(item.filename)
              })
              body.images = pictures
          }
          if (req.files['cover_image'] &amp;&amp; req.files['thumbnail_image']) {
              body.coverImage = req.files['cover_image'][0].filename;
              body.thumnbnailImage = req.files['thumbnail_image'][0].filename;
          }
  
          let product = await saveProduct(body)
          if (product) {
              generateResponse(product.success, product.message, product.data, res)
          }
      } else {
          generateResponse(false, "Please provide complete info", null, res)
      }
  } catch (err) {
      console.log('----------Error---------', err)
      generateResponse(false, 'Error occured, 404 not found!', err, res)
     }
   }
  </code></pre>
  
  <p>I have <code>angular7</code> on client-side and have image upload like this in <code>component.html</code> </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form enctype="multipart/form-data"&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;input type="text" name="name" nbInput fullWidth placeholder="Name" [(ngModel)]="product.name" [ngModelOptions]="{standalone: true}"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;nb-select [(ngModel)]="product.category" name="category" class="type-select" style="display: initial;" (selectedChange)="getBrands()"&gt;
                  &lt;nb-option value="1"&gt;Select Category&lt;/nb-option&gt;
                  &lt;nb-option *ngFor="let category of allCategories" value="{{category._id}}"&gt;{{category.displayLabel}}&lt;/nb-option&gt;
              &lt;/nb-select&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;nb-select [(selected)]="product.brand" name="brand" class="type-select" style="display: initial;"&gt;
                  &lt;nb-option value="1"&gt;Select Brand&lt;/nb-option&gt;
                  &lt;nb-option *ngFor="let brand of categoryBrands" value="{{brand._id}}"&gt;{{brand.name}}&lt;/nb-option&gt;
              &lt;/nb-select&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;tag-input [(ngModel)]="selectedSizes" [ngModelOptions]="{standalone: true}" theme='bootstrap' placeholder="Enter sizes" secondaryPlaceholder="Enter sizes"&gt;&lt;/tag-input&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;tag-input [(ngModel)]="selectedColors" [ngModelOptions]="{standalone: true}" theme='bootstrap' placeholder="Enter colors" secondaryPlaceholder="Enter colors"&gt;&lt;/tag-input&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;input type="text" name="desc" nbInput fullWidth placeholder="Description" [(ngModel)]="product.description" [ngModelOptions]="{standalone: true}"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;input type="number" name="price" nbInput fullWidth placeholder="Unit Price" [(ngModel)]="product.price" [ngModelOptions]="{standalone: true}"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;input type="number" name="quantity" nbInput fullWidth placeholder="Quantity" [(ngModel)]="product.quantity" [ngModelOptions]="{standalone: true}"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;input type="number" name="discount" nbInput fullWidth placeholder="Discount (Option)" [(ngModel)]="product.discount" [ngModelOptions]="{standalone: true}"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;div class="custom-file mb-3"&gt;
                  &lt;input type="file" name="thumbnail" class="custom-file-input" id="customFile" (change)="onThumbnailImageChanged($event)" [(ngModel)]="product.thumnbnailImage" [ngModelOptions]="{standalone: true}"&gt;
                  &lt;label class="custom-file-label" id="ti"&gt;Select Thubnail Image&lt;/label&gt;
              &lt;/div&gt;
              &lt;p *ngIf="isFileError" style="color:red;font-size:11px"&gt;{{fileErrorMsg}}&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-12"&gt;
              &lt;div class="custom-file mb-3"&gt;
                  &lt;input type="file" name="cover" class="custom-file-input" id="customFile" (change)="onCoverImageChanged($event)" [(ngModel)]="product.coverImage" [ngModelOptions]="{standalone: true}"&gt;
                  &lt;label class="custom-file-label" id="ci"&gt;Select Cover Image&lt;/label&gt;
              &lt;/div&gt;
              &lt;p *ngIf="isFileError" style="color:red;font-size:11px"&gt;{{fileErrorMsg}}&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The issue which i am facing is that i am receiving object and images files in the <code>product.controller.js</code> in <code>req.body</code> but inside my <code>api.routes.js</code> in <code>multer</code> storage function i am not getting my body object in <code>req.body</code>. Because in my <code>req.body</code> i want to get my object with the help of which i have to construct a path for image uploading. How can i get my body inside <code>multer</code> storage function?</p>