req.body returns undefined code example
Example 1: req.body is undefined
var bodyParser = require('body-parser')
var app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
Example 2: getting empty req.body
If testing the API using POSTMAN, ensure that 'Content-Length' header is active and set to <calculated when request is sent>.