title: POST Request not working - MongDB and Express JS using Mongoose
body: <p>I started working on a MERN App and am trying to write a restful api. Code is working fine. But POST Requests are not working.</p>
  
  <p>moviemodel.js</p>
  
  <pre><code>const mongoose = require('mongoose')
  
  const Schema = mongoose.Schema
  
  const Movie = new Schema(
  {
      name: { type: String, required: true },
      time: { type: [String], required: true },
      rating: { type: Number, required: true },
  },
      { timestamps: true },
  )
  
  module.exports = mongoose.model('users', Movie)
  </code></pre>
  
  <p>moviectrl.js</p>
  
  <pre><code>const Movie = require('../models/moviemodel')
  
  createMovie = (req, res) =&gt; {
  const body = req.body
  
  if (!body) {
      return res.status(400).json({
          success: false,
          error: 'You must provide a movie',
      })
  }
  
  const movie = new Movie(body)
  
  if (!movie) {
      return res.status(400).json({ success: false, error: err })
  }
  
  movie
      .save()
      .then(() =&gt; {
          return res.status(201).json({
              success: true,
              id: movie._id,
              message: 'Movie created!',
          })
      })
      .catch(error =&gt; {
          return res.status(400).json({
              error,
              message: 'Movie not created!',
          })
      })
  }
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>const express = require('express')
  const bodyParser = require('body-parser')
  const cors = require('cors')
  var MongoClient = require('mongodb').MongoClient;
  const movieRouter = require('./routes/movierouter')
  
  
  const app = express()
  const apiPort = 3000
  
  app.use(bodyParser.urlencoded({ extended: true }))
  app.use(cors())
  app.use(bodyParser.json())
  
  MongoClient.connect('mongodb://127.0.0.1:27017/cinema', { useNewUrlParser: 
  true }, function(err, client) {
  const db = client.db('cinema')
  if(err) throw err;
  console.log('Successfully connected')
  })
  
  app.get('/', (req, res) =&gt; {
  res.send('Hello World!')
  })
  
  app.use('/api', movieRouter)
  
  app.listen(apiPort, () =&gt; console.log(`Server running on port 
  ${apiPort}`))
  </code></pre>
  
  <p>movierouter.js</p>
  
  <pre><code>const express = require('express')
  
  const MovieCtrl = require('../controllers/moviectrl')
  
  const router = express.Router()
  
  router.post('/movie', MovieCtrl.createMovie)
  router.put('/movie/:id', MovieCtrl.updateMovie)
  router.delete('/movie/:id', MovieCtrl.deleteMovie)
  router.get('/movie/:id', MovieCtrl.getMovieById)
  router.get('/movies', MovieCtrl.getMovies)
  
  module.exports = router
  </code></pre>
  
  <p>When I send a POST Request using the link localhost:3000/api/movie and send a JSON Data through Postman. There is no response.</p>
  
  <p><a href="https://imgur.com/a/l6GvDbu" rel="nofollow noreferrer">https://imgur.com/a/l6GvDbu</a></p>