title: Req.body is Empty in Node Js
body: <p>In my Node application I am trying to view request.body object to check for elements that are coming inside of it but <code>console.log(req.body)</code> revels that its empty. Here are my files.</p>
  
  <p><code>app.js</code> file below</p>
  
  <pre><code>var express = require("express");
  var app = express();
  var mongoose = require("mongoose");
  var nationalPark = require("./models/NationalParks");
  
  
  
  //config
  mongoose.connect('mongodb://localhost/National_Parks', {useNewUrlParser: true, useUnifiedTopology: true}).catch(function(reason){
      console.log('Unable to connect to the mongodb instance. Error: ', reason);
  });
  app.set('view engine', 'ejs');
  var bod = require("body-parser");
  app.use(bod.urlencoded({extended:true}));
  app.use(bod.json());
  
  
  app.use(express.static(__dirname + '/resources'));
  
  
  //Routes
  app.get("/",function(req,res){
      nationalPark.find({},function(err,nationalParks){
          if(err){
              console.log(err);
          }else{
  
              res.render("home",{nationalParks:nationalParks});
          }
      })
  
  });
  
  app.get("/home",function(req,res){
      nationalPark.find({},function(err,nationalParks){
          if(err){
              console.log(err);
          }else{
              console.log(nationalParks);
              res.render("home",{nationalParks:nationalParks});
          }
      })
  });
  
  app.get("/login",function(req,res){
      res.render("login");
  });
  app.get("/signup",function(req,res){
      res.render("signup");
  });
  app.get("/logout",function(req,res){
      res.render("home");
  });
  
  app.get("/NationalPark",function(req,res){
      console.log(park.park)
   res.render("NationalPark",{park:park.park});
  });
  
  app.post("/NationalPark",function(req,res){
  
        console.log(req.body);
      res.render("NationalPark");
  });
  app.get("/post",function(req,res){
      res.render("post");
  });
  app.get("/post-display",function(req,res){
      res.render("post-display");
  });
  app.get("/profile",function(req,res){
      res.render("profile");
  });
  
  //listening port
  app.listen(3000,function(){
      console.log("Server started");
  });
  </code></pre>
  
  <p>Here is my <code>home.ejs</code>  file</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;!-- Required meta tags --&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
  
      &lt;!-- Bootstrap CSS --&gt;
      &lt;link href="https://fonts.googleapis.com/css?family=Pacifico&amp;display=swap" rel="stylesheet"&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"&gt;
      &lt;link rel="stylesheet" type="text/css" href="/css/national-parks.css"&gt;
  
  
    &lt;/head&gt;
    &lt;body&gt;
  
  
          &lt;div class="container" id="headContainer"&gt;
            &lt;div class="row"&gt;
              &lt;div class="col-2"&gt;
                &lt;nav class="nav flex-column"&gt;
                  &lt;a class="nav-link active text-white" href="/login"&gt;Login&lt;/a&gt;
                  &lt;a class="nav-link active text-white" href="/signup"&gt;Sign Up&lt;/a&gt;
                  &lt;a class="nav-link active text-white" href="/logout"&gt;Logout&lt;/a&gt;
                &lt;/nav&gt;
              &lt;/div&gt;
  
              &lt;div class="col-10" id="heading"&gt;
                &lt;h1 class="display-3"&gt;National Parks Observer&lt;/h1&gt;
                &lt;p class="lead"&gt;Site Dedicated to Indian National Parks&lt;/p&gt;
               &lt;/div&gt;
  
  
           &lt;/div&gt;
          &lt;/div&gt;
  
  
  
  
          &lt;div class="container" id="postings"&gt;
  
           &lt;%  var r=Math.round(nationalParks.length/3); %&gt;
           &lt;% var x = 1; %&gt;
           &lt;% var elementCount = 3; %&gt;
           &lt;% var constant = 3; %&gt;
           &lt;% var start=0; %&gt;
           &lt;% while(x&lt;=r){ %&gt;
            &lt;div class="row"&gt;
  
             &lt;% for(var k=start;k&lt;elementCount;k++){ %&gt;
  
              &lt;div class="col-4"&gt;
                &lt;div class="card"&gt;
  
                 &lt;form method="POST" action="/NationalPark"&gt;  
                  &lt;img class="card-img-top" src=&lt;%=nationalParks[k].imageurl %&gt; alt="Card image cap"&gt;
  
  
                  &lt;h5 class="card-title" name="parktitle" id="title"&gt;&lt;%=nationalParks[k].nationalPark %&gt;&lt;/h5&gt;
  
                    &lt;button type="submit" class="btn btn-primary btn-sm""&gt;View Page&lt;/button&gt;
  
                  &lt;/form&gt; 
  
                &lt;/div&gt;
             &lt;/div&gt;
  
             &lt;% } %&gt;
             &lt;%  start=start+constant; %&gt;
             &lt;%   elementCount=Math.min(elementCount+constant,nationalParks.length); %&gt;
  
  
            &lt;/div&gt;
  
            &lt;% x++; }  %&gt;
  
  
  
  
  
  
  
  
  
  
          &lt;/div&gt;
  
  
          &lt;br&gt;
          &lt;br&gt;
          &lt;br&gt;
  
  
  
      &lt;!-- Optional JavaScript --&gt;
      &lt;!-- jQuery first, then Popper.js, then Bootstrap JS --&gt;
      &lt;script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"&gt;&lt;/script&gt;
  
      &lt;script src="/javascript/national-park.js"&gt;&lt;/script&gt;     
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>at following post method in <code>app.js</code> </p>
  
  <pre><code>app.post("/NationalPark",function(req,res){
  
        console.log(req.body);
      res.render("NationalPark");
  });
  </code></pre>
  
  <p><code>console.log(req.body)</code> simply prints <code>{}</code></p>
  
  <p>Why is it happening, am I missing something? Will deeply appreciate your help. Thanks in advance. </p>