Express app.set, vs app.use Express app.set, vs app.use express express

Express app.set, vs app.use


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.


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.