11

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.

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

2 Answers 2

25

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

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() 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.

Sign up to request clarification or add additional context in comments.

Comments

3

app.use is used to register a middleware. e.g. if you defined your routs to different file and created a module out of it then you can register the module use app.use

app.set is mainly used to store and retrieve variables.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.