一:新建Express文件夹
二:在里面打开PowerShell
三:安装Express 应用程序生成器
使用命令:npx express-generator
四:用VScode编辑器打开项目
注意:打开app.js文件, 将其中的
app.use(express.urlencoded({ extended: false }));
改成为
app.use(express.urlencoded({ extended: true}));
五:修改其它信息
六:在index.js文件中添加接口数据
router.post('/index',(req, res, next)=>{
console.log(req.body);
res.send({
msg:'成功2',
data:{
arr1:[{
id: 1,
name: '张三',
age: 30
}],
arr2:[{
id: 2,
name: '李四',
age: 20
}]
}
})
})
七:重新启动PowerShell
使用命令:
npm i
npm start
七:用postman测试
本地接口:http://localhost:8989/index
其它接口吧localhost改成其它地址即可比如: 127.1.1.1