随着express升级,bodyParser从express中被分离了出来,所以,在使用express新版本的时候,须要npm install body-parser 来安装bodyParser。
express
在app.js中要引入bodyParser。npm
var bodyParser = require('body-parser');app
其次,须要在app.js中use bodyParser。ui
app.use(bodyParser());url
最后,须要给bodyParser提供参数。code
'Content-Type': 'application/x-www-form-urlencoded' orm
对于bodyParser的参数,根据须要解析的文件类型来进行设置,参数类型有不少种,能够查看具体文献。io
如何发现3中的有过时的状况,将改成app.use(bodyParser.urlencoded({extended:false}));form