必知 Express和 MVC

40 阅读1分钟

中间件

image.png

image.png

image.png

简单但重要的发送/响应


app.use(express.json())

 

app.post('/friends', (req, res) => {

if(!req.body.name){

return res.status(400).json({

error:'Missing friend name'

})

}

 

const newFriend = {

name: req.body.name,

id: friends.length

}

 

friends.push(newFriend)

 

res.json(newFriend)

})

 

 

app.get('/friends', (req, res) => {

res.json(friends)

})

image.png

image.png

image.png

MVC(Model View Controller)

image.png

image.png

image.png

image.png

image.png

添加 router

image.png

image.png

Restful Api

image.png

image.png

CRUD

CRUD 工程师其实很多业务都是以这些操作为主

image.png

Template engines

image.png

仓库

github.com/huanhunmao/…

感谢点点 star ~