express獲取數據的方法

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獲取參數了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章