body-parser 用法

时间:2023-03-09 09:54:55
body-parser 用法

1、下载 body-parser 模块  :   npm install body-parser

2、require body-parser 模块(引入),并用一个变量接收(此处栗子变量为 bodyparser)

3、将 bodyparser 注册为中间件

const express = require('express')
// 在此处 require body-parser 模块
const bodyparser = require('body-parser') const app = express()
app.listen(3001, () => console.log('app is running...')) // 在此处 use 这个 bodyparser 中间件
app.use(bodyparser.urlencoded({ extended: false }))