body-parser处理post请求
安装模块body-parser使用中间件加载即可
- npm i body-parser
js
const express = require('express')
const app = express()
const port = process.env.PORT || 8000
app.listen(port, () => {
console.log('服务启动成功:http://localhost:8000')
})
// 支持post请求,前端对象形式传递过来的,application/x-www-form-urlencoded(默认)
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())