express沒有內置的POST請求API,但是有聽說將body-parser
內置到express中了。但是我試了直接使用不了。所以還是直接安裝第三方包
使用第三方包body-parser
安裝
npm install body-parser
在app.js中
var bodyParser = require('body-parser')
// 配置模板引擎和 body-parser 一定要在 app.use(router) 掛載路由之前
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())