express的中间件body-parse

Posted flyerya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了express的中间件body-parse相关的知识,希望对你有一定的参考价值。

1. 安装

npm install body-parser

2.

var bodyParser = require(‘body-parser‘);

//只要加入这个配置,在req请求对象上会多出来一个属性
//parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded( extended: false ))
//parse application/json
app.use(bodyParser.json())

 app.post(‘/test‘, function(req, res)
    console.log(req.body);
 );

 

 

以上是关于express的中间件body-parse的主要内容,如果未能解决你的问题,请参考以下文章