Performance: Route matching order matters
MEDIUM IMPACT
This affects server response time and resource usage by determining how quickly the correct route handler is found.
app.get('/about', (req, res) => { res.send('About page'); }); app.get('/:id', (req, res) => { res.send('ID route'); });
app.use((req, res, next) => { next(); });
app.get('/:id', (req, res) => { res.send('ID route'); });
app.get('/about', (req, res) => { res.send('About page'); });| Pattern | Route Checks | Middleware Calls | Response Delay | Verdict |
|---|---|---|---|---|
| General route before specific | Many unnecessary checks | Extra middleware runs | Increased delay | [X] Bad |
| Specific route before general | Minimal checks | Only needed middleware | Faster response | [OK] Good |