Or use the urlencoded
middleware (place it before any of your routes):
app.use(express.urlencoded());
...
app.post('/sendinfo', function(req, res) {
// req.body will now contain the object you described
...
});
Updated July 16, 2017
urlencoded
removed from express
node module in the latest version so please use this for now
const bodyParser = require("body-parser");
/** bodyParser.urlencoded(options)
* Parses the text as URL encoded data (which is how browsers tend to send form data from regular forms set to POST)
* and exposes the resulting object (containing the keys and values) on req.body
*/
app.use(bodyParser.urlencoded({
extended: true
}));
/**bodyParser.json(options)
* Parses the text as JSON and exposes the resulting object on req.body.
*/
app.use(bodyParser.json());