node.js中使用body-parser完成对application/x-www-form-urlencoded格式请求体内容的解析

20 阅读1分钟

下载依赖

  • npm i body-parser

引入并赋值给变量

  • const bodyParser = require("body-parser")

在全局中间件中使用bodyParser.urlencoded()

  • app.use(bodyParser.urlencoded({ extended: false }))
    extended: false表示只支持非常基础的类型解析如字符串和数组。如果需要解析嵌套的对象结构,则应该设置extended: true