express serves index.html even when my routing is to a different file express serves index.html even when my routing is to a different file express express

express serves index.html even when my routing is to a different file


This is because you declared app.use(express.static) before app.get('/'). Express checks routes in the order they are declared, and since index.html is a default filename which is used by static middleware, it shows index.html content.

To fix this you may either put app.use(express.static) after app.get('/'), or set index property of static second argument to non-existing file (false doesn't seem to work):

app.use(express.static(path.join(__dirname, 'public'), {index: '_'}));