title: bExpress bodyparser not configuing properly
body: <p>I have a server.js file, where i have a <code>trainer route</code></p>
  
  <p>which is used for creating some routes in express, but whenever i run the program, it gives me a typeError</p>
  
  <pre><code>firstName: req.body.firstName,                       ^
  
  TypeError: Cannot read property 'body' of undefined
  </code></pre>
  
  <p>here is my entire server.js file. I have configured the correct bodyparsers for express, yet it still gives me the same error</p>
  
  <p>Server.js</p>
  
  <pre><code>const express = require('express');
  const properties = require('./config/properties');
  const db = require('./config/database');
  const app = express();
  const bodyParser = require('body-parser');
  const log = require('morgan')('dev');
  const cors = require('cors');
  
  
  // call the database connectivity function
  db();
  
  
  
  
  //configure middleware
  app.use(log);
  app.use(cors());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  
  //parsers
  const router = express.Router();
  
  //routes
  const trainerRoutes = require('./api/trainers/trainer.routes');
  
  
  
  //configure routes
  app.use('/api', router);
  
  trainerRoutes(router);
  
  
  app.listen(properties.PORT, (req, res)=&gt;{
      console.log(`Server running on ${properties.PORT} port`)
  });
  </code></pre>
  
  <p>why does this problem occur?</p>
  
  <p>EDIT:</p>
  
  <p>here is the function in which the error occurs, this is in the trainer.controller.js file:</p>
  
  <pre><code>exports.updateTrainer = function(req, res, next) {
      const trainer = {
          firstName: req.body.firstName,
          lastName: req.body.lastName,
          biography: req.body.description,
          certificates: req.body.certificates
      };
      Trainer.update({_id: req.params.id}, trainer, function(err, trainer) {
          if(err) {
              res.json({
                  error : err
                  //should make a log message here
              })
          }
          res.json({
              message : "Trainer updated successfully"
          })
      })
  };
  
  </code></pre>
  
  <p>trainer.routes.js file</p>
  
  <pre><code>module.exports = function(router) {
      router.post('/create', Trainer.createTrainer);
      router.get('/get', Trainer.getAllTrainers);
      router.get('/get/:name', Trainer.getTrainer);
      router.put('/update/:id', Trainer.updateTrainer());
      router.delete('/remove/:id', Trainer.removeHero());
  };
  </code></pre>