Arash Fallahi
Arash Fallahi

Reputation: 23

What's the meaning of mounting in Express documentation?

Here, in the entry for app.use, has said that [app.use] "Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path." I want to know that what is the meaning of "mount" here. I don't find a relevant meaning in dictionary for "mount".

Upvotes: 2

Views: 748

Answers (1)

jfriend00
jfriend00

Reputation: 707926

In this context, "mounts" could be replaced with "registers". "Registers the specified middleware function or functions at the specified path".

The idea is that you have a middleware function and you want to add it to your Express server it so you use app.use() to tell Express about it so that it will add it to the chain of middleware that it will consider for each incoming request.

Internally, Express has an array of middleware functions and an optional path for each one. When a new request comes in, it starts at the beginning of the array and calls the first middleware function whose path matches the incoming request. If that middleware calls next(), then Express looks for the next one to match and calls it and so on...

The "mounts" in your statement is adding a middleware function and optional path to this array so it can be matched against incoming requests.

Upvotes: 7

Related Questions