它是Express框架的中間體,可以用來解析請求體內(nèi)容。
引入模塊
const bodyParser = require('body-parser')
四種使用場景:
1.處理表單提交時的內(nèi)容類型/application/x-www-form-urlencoded
app.use(bodyParser.urlencoded())
2.json數(shù)據(jù)格式的請求參數(shù)
app.use(bodyParser.json())
3.處理文本數(shù)據(jù)
bodyParser.text(options)
4.處理Buffer流數(shù)據(jù)
bodyParser.raw(options)