编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

话说前端补充篇-express中间件、art-template模版

wxchong 2024-08-02 09:04:45 开源技术 17 ℃ 0 评论

分享兴趣,传播快乐,增长见闻,留下美好!亲爱的您,这里是Learning Yard新学苑。今天小编为大家带来“话说前端补充篇-express中间件、art-template模版”。

Share interest, spread happiness, increase knowledge, and leave beautiful. Dear, this is the LearingYard Academy! Today, the editor brings the . Welcome to visit!


Express 能做什么:搭建两种服务器,分别是:Web 网站服务器:专门对外提供 Web 网页资源的服务器。API 接口服务器:专门对外提供 API 接口的服务器。使用 Express,我们可以方便、快速的创建 Web 网站的服务器或 API 接口的服务器。

What can Express do: build two kinds of servers, namely: Web site server: a server that provides Web page resources to the outside world. API interface server: a server that provides API interfaces to the outside world. With Express, we can easily and quickly create a server of a Web site or an API interface server.

Express 的使用:

Use of Express:

Express获取参数 :通过 req.query 对象,可以访问到客户端通过查询字符串的形式,发送到服务器的参数:

Get parameters by Express: through the req.query object, you can access the parameters sent by the client to the server in the form of query strings:

Express获取参数:通过 req.params 对象,可以访问到 URL 中,通过 : 匹配到的动态参数,托管多个静态资源目录:如果要托管多个静态资源目录,请多次调用 express.static() 函数:访问静态资源文件时,express.static() 函数会根据目录的添加顺序查找所需的文件。

Express gets parameters: you can access the URL through the req.params object, and host multiple static resource directories through the matched dynamic parameters: if you want to host multiple static resource directories, please call the express.static () function several times: when accessing static resource files, the express.static () function will look for the required files according to the order in which the directories are added.

Express路由 :为了方便对路由进行模块化的管理,Express 不建议将路由直接挂载到 app 上,而是推荐将路由抽离为单独的模块。将路由抽离为单独模块的步骤如下:1. 创建路由模块对应的 .js 文件2. 调用 express.Router() 函数创建路由对象3.向路由对象上挂载具体的路由4. 使用 module.exports 向外共享路由对象5.使用 app.use() 函数注册路由模块。

art-template 运行速度:常见模板引擎的性能对比:

Express routing: In order to facilitate the modular management of routing, Express does not recommend directly mounting the routing on the app, but recommends separating the routing into separate modules. The steps of separating a route into separate modules are as follows: 1. Create a. js file corresponding to the routing module; 2. Call the express.Router () function to create a routing object; 3. Mount a specific route on the routing object; 4. Share the routing object with module.exports; 5. Register the routing module with the app.use () function.

Running speed of art-template: performance comparison of common template engines;


如果您对今天的文章有独特的想法,欢迎给我们留言,让我们相约明天,祝您今天过得开心快乐。

That's all for today's sharing. If you have a unique idea about the article, please leave us a message, and let us meet tomorrow. I wish you a nice day!

翻译:Google翻译

本文由LearningYard新学苑原创,如有侵权,请联系删除。

文字&排版|橙猫猫

审核|闫庆红

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表