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 Repl.it: 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 https://boilerplate-express-4.ericdominguez.repl.co/public 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

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.