// 导入
const express = require('express')
const multer = require('multer');
// 配置 处理formdata
const upload = multer({dest:'uploads/'})
const app = express()
app.use(express.urlencoded())
// 登录
app.post('/api/login',(req,res)=>{
console.log(req.body);
res.send({
"status": 0,
"message": "登录成功",
})
})
// 个人信息
app.get('/my/user/userinfo',(req,res)=>{
res.send({
"status": 0,
"message": "获取用户信息成功",
"data": {
"id": 1,
"username": "****",
"nickname": "****",
"email": "*****@qq.com",
"user_pic": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAe"
}
})
})
// 发布文章
app.post('/my/article/add',upload.single('cover_img'),(req,res)=>{
//文件信息存放在req.file
console.log(req.file);
//其他信息存放在req.body
console.log(req.body);
res.send({
"status": 0,
"message": "添加文章成功"
})
})
app.listen(8080,function(){
console.log(8080);
})
app.post('/my/article/add',upload.single('cover_img'),(req,res)=>{
//文件信息存放在req.file
console.log(req.file);
//其他信息存放在req.body
console.log(req.body);
res.send({
"status": 0,
"message": "添加文章成功"
})
})
app.listen(8080,function(){
console.log(8080);
})
然后CMD运行这个node server.js
之后使用postman来测试接口.