📜  express.json 与 bodyparser.json - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:52.954000             🧑  作者: Mango

代码示例2
const express = require('express')
const bodyParser = require('body-parser')

const app = express()

// parse application/x-www-form-urlencoded
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))
})