Hello, in one of the youtube tutorials, the guy used an express.static(...)
middleware. I know of course that it is used to point to the folder where your static files are. But when he went to the http://localhost:3000/
in the browser he was automatically served with the index.html
file. It wouldn’t be strange if he set the route like app.get('/', (req, res) => res.send('index.html'))
but he didn’t. All he did in his code was:
- Bring in the server by express
- Use the middleware that I have mentioned above
- Set the server to listen on port 3000
So my question is how did it happen that by only using the express.static(...)
middleware he was able to serve the index.html
file without setting any route?