Basic Node and Express: Serve Static Assets - app.use and expres.static questions

In this lesson we are instructed to:

Mount the express.static() middleware to the path /public with app.use()

The lesson says that:

A middleware needs to be mounted using the method app.use(path, middlewareFunction)

There’s no concrete example to reference in the lesson, but going off of the information provided I arrived at the following code:

app.use('/public', express.static);

I set path to ‘/public’ because that is the path we were instructed to mount the middleware to, and set middlewareFunction to express.static because that is how you would reference the function, right? Adding the () (i.e express.static()) would invoke the function, but we don’t want that - the second parameter says we want to pass the middleware function.

So I did this and this was incorrect. So I looked around online. I saw the following:


Which of course, is the solution (well, it’s missing the first parameter in app.use). However, this still doesn’t add up for me, because of the following:

I looked at the documentation for app.use() and as per the documentation:

the arguments for app.use() are a path and a callback function (the middleware). It also says it can take an array of middleware functions instead of just one middleware function - so we can pass in either a function or an array of functions to this parameter. However, when we pass in express.static('./public'), my understanding is that we are first invoking express.static('./public'), which returns an object - as per:

The documentation for app.use() doesn’t have any mention of how the method would handle being passed an object where the middleware function should be.

Is there something I am misunderstanding (I’m sure there is)? I think a clarification of what exactly app.use() accepts as arguments and exactly what express.static() returns might be helpful (I just found that express.static() returns some object, but cannot find an example of what that object is).

Thanks in advance!