Express中接受post请求参数需要借助第三方包 body-parser
1.安装
2.在app.js中引入
//引入express框架
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
//拦截所有请求
//extended:false 方法内部使用querystring模块处理请求参数的格式
//extended:true 方法内部使用第三方模块qs处理请求参数的格式
// 解析application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended:false}))
//解析application/json
//app.use(bodyParser.json())
app.post('/add',(req,res)=>{ //接收post请求参数 res.send(req.body);})
app.listen(3000, function () { console.log('Example app listening on port 3000!')})