一.安装
npm install --save body-parser
二.使用方法
实例:
var express = require('express')
引包
var bodyParser = require('body-parser')
var app = express()
// parse application/x-www-form-urlencoded
加入bodyparser就会获得res的body属性了
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.write('you posted:\n')
res.end(JSON.stringify(req.body, null, 2))})