Performance: Why middleware is Express's core concept
MEDIUM IMPACT
Middleware affects how requests are processed and how fast the server responds, impacting server response time and throughput.
app.use(async (req, res, next) => { await someAsyncTask(); next(); });
app.use((req, res, next) => {
// heavy synchronous task
for(let i = 0; i < 1e8; i++) {}
next();
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking synchronous middleware | N/A | N/A | N/A | [X] Bad |
| Asynchronous non-blocking middleware | N/A | N/A | N/A | [OK] Good |