工作生活

使用body-parser处理前端post请求

2019-07-01  本文已影响0人  Tme_2439

安装模块body-parser使用中间件加载即可

npm i body-parser

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())
上一篇 下一篇

猜你喜欢

热点阅读