express获取数据的方法

1,465 阅读1分钟

express获取数据的方法

一.get请求(获取url上面的参数)

req.query

二.post请求(获取请求体里面的参数)

1.先安装body-parser

npm install body-parser --save-dev

2.使用

const bodyParser = require('body-parser')	

app.use(bodyParser.urlencoded({
    extended: false
}))
app.use(bodyParser.json())

//这样就可以直接使用req.body获取参数了