Express核心概念~路由

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/84715011

1) 官方概念:

路由是指如何定义应用的端点(URIs)以及如何响应客户端的请求。

2) 通俗概念:

通过制定不同的路径,调用对应处理用户的请求。

3) express路由支持多种http请求方式。如:

get

?

post

一般是用户通过表单提交数据

delete

put

4)路由的链式请求

请求同一个路径,可以选择用get或者post方式,所以,为了节省代码,变得更加清晰,express支持

app.get("xxxx", function(req, res){})
    .post("xxxx", function(req, res){})

5)路由的模块化书写方式

写一个大型项目,必然是要讲究模块化的,将同类功能,写在同一个文件夹中。

const express = require("express");
const router = express.Router();
router.post("xxxx", function(req, res){});
module.exports = router;

通过这样的方式按照功能,划分到不同的路由中处理。

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/84715011