req.body
Contains key-value pairs of data submitted in the request body. By default, it is undefined
, and is populated when you use body-parsing middleware such as body-parser and multer.
The following example shows how to use body-parsing middleware to populate req.body
.
var app = require('express')(); var bodyParser = require('body-parser'); var multer = require('multer'); // v1.0.5 var upload = multer(); // for parsing multipart/form-data app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.post('/profile', upload.array(), function (req, res, next) { console.log(req.body); res.json(req.body); });
Please login to continue.