Express app.set与app.use的比较 [英] Express app.set, vs app.use

查看:99
本文介绍了Express app.set与app.use的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这可能是一个很菜鸟的问题,关于这件事的文章很多,但是我很难找到一个对我来说很清楚的解释,这是有道理的.我也没有在stackoverflow中找到这个问题.

I realize this is probably a pretty noob question, and that there's a ton of articles about this very thing, but I'm having a super hard time finding an explanation that's clear to me, and that makes sense. I also didn't find this question in stackoverflow.

我的问题很简单:明确地说,app.set和app.use有什么区别?

My question is simply: In express, what's the difference between app.set, and app.use?

推荐答案

我的问题很简单:明确地说,app.set和app.use有什么区别?

My question is simply: In express, what's the difference between app.set, and app.use?

app.set(名称,数据) app 对象上存储了一个命名属性,以后可以使用 app.get(name). app.set()的某些属性名称具有预定的效果,这些效果在快速文档,其工作方式类似于配置选项.

app.set(name, data) stores a named property on the app object that can be retrieved later with app.get(name). Some property names for app.set() have predetermined effects that are described in the Express doc and work like configuration options.

app.use()注册一个中间件回调,该回调将作为传入HTTP请求的请求处理程序链的一部分.根据参数,将针对所有传入请求或仅针对某些请求调用中间件.

app.use() registers a middleware callback that will be part of the request handler chain for incoming http requests. Depending upon the arguments, the middleware will either be called for all incoming requests or only for certain requests.

两者是完全不同的操作,不能直接比较.

The two are complete different operations that are not directly comparable.

这篇关于Express app.set与app.use的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆