Performance: express-validator setup
MEDIUM IMPACT
This affects server response time and user experience by validating input before processing requests.
import { body, validationResult } from 'express-validator'; app.post('/submit', [ body('email').isEmail(), body('password').isLength({ min: 6 }) ], (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } res.send('Success'); });
app.post('/submit', (req, res) => { if (!req.body.email || !req.body.password) { return res.status(400).send('Missing fields'); } // manual validation logic here // proceed with processing res.send('Success'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual validation in route handler | N/A (server-side) | N/A | N/A | [X] Bad |
| express-validator middleware usage | N/A (server-side) | N/A | N/A | [OK] Good |