bodyparser 用來解析post的請求取代了 原生的 req.on 的方式 但是只能取到ajax 和表單的數據 ,取不到上傳的文件類型。
let express = require('express'); let bodyParser = require('body-parser'); let app = express();
-
//app.use(bodyParser.urlencoded({extended:false}));//解析 x-www-form-urlencoded
-
app.use(bodyParser.text());//將所有的數據以文本格式字符串的返回 form表單中 text-plain
-
app.use(bodyParser.raw());//解析二進制數據
-
app.use(bodyParser.urlencoded({extended:false}));//解析 x-www-form-urlencoded app.use(bodyParser.json());//無法演示 解析json數據依賴於urlencoded模塊 必須同時應用
同時用時效果如下: