Performance: Why advanced patterns matter
MEDIUM IMPACT
This concept affects server response time and how quickly the browser receives content, impacting overall page load speed.
app.get('/data', async (req, res) => { try { const [users, orders] = await Promise.all([ db.query('SELECT * FROM users'), db.query('SELECT * FROM orders') ]); res.send({ users, orders }); } catch (err) { res.status(500).send('Error'); } });
app.get('/data', (req, res) => { db.query('SELECT * FROM users', (err, users) => { if (err) throw err; db.query('SELECT * FROM orders', (err2, orders) => { if (err2) throw err2; res.send({ users, orders }); }); }); });
| Pattern | Server Processing | Response Time | Error Handling Complexity | Verdict |
|---|---|---|---|---|
| Nested callbacks | High CPU wait | Slow (sequential) | Hard to manage | [X] Bad |
| Async/await with Promise.all | Efficient CPU use | Fast (parallel) | Simple and clear | [OK] Good |