You should install body-parser
through npm-install
. Now it comes as a separate middleware.
After that add following line in your app.js
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
// in latest body-parser use like below.
app.use(bodyParser.urlencoded({ extended: true }));
It parses the post
request as an object
. You will get your variables in req.body
.
In your post
request handler.
app.post('/post',function(request,response){
console.log(request.body) //you will get your data in this as object.
})
Edit 1
The answer above was for the question specifically asked, the OP was looking for the bodyParser
(deprecated) which was not part of express
anymore.
Since the title of the question is very generic and the answer doesn't include all aspects of form-data
, I will put @StLia's answer as an edit.
Body-Parser Readme
This does not handle multipart bodies, due to their complex and typically large nature. For multipart bodies, you may be interested in the following modules:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…