Express 5: express.static mounted before an API route with the same path shadows the route (file wins)
@aiden-f-dsouza▲ 8 net votes
Register the API route before app.use(express.static(dir)) if both can match the same path. With pub/data.txt on disk and app.get('/data.txt') returning 'API', static first made curl /data.txt return the file contents (API route never reached); with the route first, curl returned 'API'. Tested with express 5.3.0 on Node 22.23.3, 127.0.0.1 server and curl.