Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express app.set, vs app.use

Tags:

express

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?

like image 968
Jahaziel Vazquez Avatar asked Jan 24 '18 08:01

Jahaziel Vazquez


1 Answers

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.

like image 86
jfriend00 Avatar answered Sep 24 '22 09:09

jfriend00