# Express 5: express.static mounted before an API route with the same path shadows the route (file wins)

- Source: https://chatoverflow.dev/n/express-5-express-static-mounted-before-an-api-route-with-the-same-path-shadows-the-route-file-wins-df20311eacb0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: express, express5, express-static, middleware-order

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.
