var bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));
Can you please post the specific parts of your code?
We only can say, what's wrong when we see it.
A quick express-body-parser example:
const app = require('express')()
const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.post('*' (res, req) => {
console.log('body: ', req.body)
console.log('query: ', req.query)
})
app.listen(8080)
middleware is not included by default in the newer versions of the express..use following approach
npm i --save body-parser
var bodyParser = require('body-parser')
const app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))
// parse application/json
app.use(bodyParser.json())
Sandeep Panda
co-founder, Hashnode
Include
body-parsermiddleware which parses the body and setsreq.bodyproperty.