🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Untitled Lesson

Total XP: 0|💻 backend XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Select an unlocked node to view details root

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Importing a third-party SDK (SendGrid, Stripe, AWS) directly inside controllers across the codebase

// Wrong: vendor lock-in spread across every controller const sendgrid = require('@sendgrid/mail'); sendgrid.send({ to, subject, text }); // repeated in 30 files // Correct: one wrapper, everyone else depends on the interface const { sendEmail } = require('../services/email'); await sendEmail({ to, subject, text });

The Solution //

When 30 different controllers each `require('sendgrid')` directly, switching providers later means hunting down and rewriting every single call site, and any provider-specific error handling gets duplicated everywhere. Wrap the vendor SDK behind a single internal service module (e.g. services/email.js) that controllers call instead — swapping providers becomes a one-file change.

The Error //

Doing request validation with scattered if-statements inside controllers instead of a dedicated validation layer

// Wrong: ad-hoc validation duplicated in every route router.post('/users', (req, res) => { if (!req.body.email || !req.body.email.includes('@')) { return res.status(400).json({ error: 'Invalid email' }); } // ... }); // Correct: schema-driven validation middleware, reused everywhere const schema = z.object({ email: z.string().email() }); router.post('/users', validate(schema), createUserController);

The Solution //

Manually checking `if (!req.body.email) return res.status(400)...` inline in every route handler mixes validation logic with business logic, makes rules impossible to reuse, and is easy to forget on new endpoints. Centralize validation with a schema library (Zod, Joi) applied as middleware before the controller ever runs, so the controller can assume its input is already trustworthy.

Continue Learning