Why Does Accessing '/public' when I'm in the '/' path work?

Good morning, I hope you are doing well

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

hi Eric, I’ve unlisted this thread as it is a duplicated issue to the one we are discussing elsewhere.

1 Like

The first one allows visitors to access a route at yourwebsite.com/public. 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 yourwebsite.com/public/index.html.

The second one allows visitors to access files at the root of your yourwebsite.com 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 yourwebsite.com/index.html.

Would this mean that the second option is best?