Confused About Wording

Good morning, I hope you are doing well

I am not sure what the method .use() does, the course says that it’s used to mount middleware (which then states that it will explain later what middleware is, so that isn’t much help). What does ‘mounting middleware mean’?

Thank you.

in “computer speak” the word mounted usually means ‘to make accessible’ in some way. For eg. you can mount a drive. Meaning that before it was mounted, you couldn’t access it, and after you mounted it, it became available for you to use.

So imagine that ‘middleware’ is some kind of program or programs and when you call use you are telling the server to make that software available (where it was not before).

hope this helps

I see, thank you.

Another question. What is the difference between these two lines of code? I read that the first one points to the /public route, but what does that mean?

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

My code on boilerplate-express (4) - Replit

The first one exposes the /public files if the route to your site is via /public (like https://mywebsite/public)

(see Randell’s response below instead)

The second one exposes the files in the root path (so the path just above the public folder) if the route to your site is via /public

If you have a folder setup like:

-rwxr--r-- 4 hbar1st hbar1st   60 Dec 20 00:06 aRootFile
drwxr-xr-x 4 hbar1st hbar1st 4096 Dec 20 00:06 public

The file aRootFile will become readable thru the 2nd line of code.
the directory public and its files will become readable through the 1st line of code.

Thank you for your patience and responses, but I am still lost. What do you mean the first exposes the /public files? I tried to access and nothing came up.

in the index.html of your replit project you have this stylesheet ref
<link rel="stylesheet" href="/public/style.css">

Before adding the app.use line of code, this stylesheet could not be accessed by the index.html.

After adding it, the stylesheet is ‘visible’ and can be applied.

Thank you! 20 characters

1 Like

The first one allows visitors to access a route at The files for this route are located on the server in a folder at the __dirname + '/public'

This means if you have a file named index.html located on the server at __dirname + '/public', a visitor would access the file at

The second one allows visitors to access files at the root of your even though the files are stored on the server at __dirname + '/public'.

This means if you have a file named index.html located on the server at __dirname + '/public', a visitor would access the file at

Thank you for your response.

  1. Is there a preferred way to mount those middlewares?

  2. What can I google to learn more about this topic? I’m still confused. It seems like its teaching me something that I could just fix with one way of writing middleware.

It depends on the app and how you want to structure the files for it. If you have a simple site that will not have different routes, then you could go with option 2. This will allow visitors to access files (i.e. index.html, someother.html, etc.) from the root of the site while have the actual files in a different folder than the root folder on the server.

Just keep going in the challenges for this curriculum section and you will see what is typically done.

Most of the time, you will probably go with the first option to keep static files (more like css or js files) accessible in a different public folder. Everyone has different approaches to this though. There is no right or wrong way and really just depends on the app being built.