How does express know this routing?

I create a simple express server and serve the static files

const express = require('express');
const app = express();

app.use(express.static(‘public’));

app.listen(3000, () => {
console.log(‘Listening on port 3000’)
})

When I head to localhost:3000, the index.html in my public directory renders for the route ’ / '. I didn’t explicitly write the route in my index.js file. How does express know this?

I’ve tried changing the file name from index.html to random.html and I get an error. CANNOT GET /

#node.js #express

4 Likes1.55 GEEK