Performance: Application-level middleware
MEDIUM IMPACT
This affects server response time and how quickly the server processes requests before sending responses.
app.use(async (req, res, next) => { await someAsyncOperation(); next(); });
app.use((req, res, next) => {
// heavy synchronous processing
for (let i = 0; i < 1e7; i++) {}
next();
});| Pattern | Middleware Calls | Blocking | CPU Usage | Verdict |
|---|---|---|---|---|
| Heavy synchronous middleware on all routes | Many | Yes | High | [X] Bad |
| Asynchronous middleware on specific routes | Few | No | Low | [OK] Good |