title: How to check req.body empty or not in node ,express?
body: <p>Below is my request body and which is sending from client side </p>
  
  <pre><code>var  credentials = {
  
  "ConsumerData": {
  
              "ConsumerStoreId": "a",
              "ConsumerUserId": "a"
          },
          "CustomerData": {
  
              "CustomerId": "2345678890"
          },
          "ErnD": {
              "UID": "3",
              "TxnDt": "1"
          },
  
          "PurD": [{
                  "ItemCode": "3456tghw3",
                  "ItemEANCode": "223222122"
  
              },
              {
                  "ItemCode": "8jghw3865",
                  "ItemEANCode": "3334443222"
  
              }
          ]
  }
  </code></pre>
  
  <p>for testing i am sending <code>var  credentials = {}</code> empty credentials </p>
  
  <p>In server side controller(node,express) i want to check req.body empty or not </p>
  
  <pre><code>if(!req.body)
  
  {
   console.log('Object missing');
  }
  if(!req.body.ConsumerData.ConsumerStoreId)
    {
    console.log('ConsumerStoreId missing');
    }
   if(!req.body.CustomerData.CustomerId)
    {
    console.log('CustomerId missing');
    }
    if(!req.body.ErnD.UID)
    {
    console.log('UID missing');
    }
      console.log('outside'); 
  </code></pre>
  
  <p>i am checking everything but alwasys its printing outside only</p>