Basic Node and Express - Serve Static Assets

After reading the docs and the FCC explanation, I’m still stuck on the concept of middleware. For example

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

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

If my comments are correct, why can’t I just write

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

Maybe this will help answer it.

Let’s say you have the following folder structure:

public
  index.html
server.js

The difference between:

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

and

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

is the first one allows you to access index.html located in your public folder off root like:
https://yoursite.com/index.html

where as the second version would force you to get to the same file like:
https://yoursite.com/public/index.html

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

And assuming your project is located on your drive in a folder with the path /home/username/project, the third version would only work if you created a new folder in the root of our drive that looked like:
/public/home/username/project/public, you put index.html in this folder, you could get to it with: https://yoursite.com/index.html`

One slight modification (removing the starting forward slash) like:

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

would allow you to put index.html in the following folder of your project:
public/home/username/project/public and access it like:
https://yoursite.com/index.html

Thank you for your response.

Just to check if I’m understanding correctly, this:

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

Could look like this:

https://yoursite.com(“/public”)(__dirname + “/public”)

For example:

app.use("/styles", express.static(__dirname + "/styles"));
// let's say the only file in styles is a css file called cool.css

is

https://yoursite.com/styles/cool.css

Would this be correct?

Yes, that would be correct.