UPDATE 2022
You can just use.
app.use(express.json())
const express = require('express')const app = express();const PORT = process.env.PORT || 3001// Calling the express.json() method for parsingapp.use(express.json())app.listen(PORT, () => { console.log(`============ API Gateway is open at ${PORT} ============= `)})
express.json() is a built-in middleware function in Express. This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser.
This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option.