Performance: Why database integration matters
This affects how quickly your web app can load and respond by managing data efficiently between the server and database.
Jump into concepts and practice - no test required
app.get('/profile', (req, res) => { const userId = req.query.id; db.query('SELECT * FROM users WHERE id = ?', [userId], (err, results) => { if (err) throw err; res.send(results[0]); }); });
app.get('/profile', (req, res) => { const userId = req.query.id; db.query('SELECT * FROM users', (err, results) => { if (err) throw err; const user = results.find(u => u.id === userId); res.send(user); }); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetching all data then filtering | N/A (server-side) | N/A | N/A | [X] Bad |
| Querying only needed data | N/A (server-side) | N/A | N/A | [OK] Good |
app.get('/users', async (req, res) => {
const users = await db.collection('users').find().toArray();
res.json(users);
});app.post('/product', (req, res) => {
const product = req.body;
db.collection('products').insertOne(product);
res.send('Product saved');
});