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’?
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).
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?
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.
Is there a preferred way to mount those middlewares?
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.