In general, an express app needs to specify the appropriate body-parser middleware in order for req.body
to contain the body.
[EDITED]
-
If you required parsing of url-encoded (non-multipart) form data, as well as JSON, try adding:
// Put this statement near the top of your module var bodyParser = require('body-parser'); // Put these statements before you define any routes. app.use(bodyParser.urlencoded()); app.use(bodyParser.json());
First, you’ll need to add body-parser to the
dependencies
property of yourpackage.json
, and then perform anpm update
. -
To handle multi-part form data, the
bodyParser.urlencoded()
body parser will not work. See the suggested modules here for parsing multipart bodies.