Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
According to the Single Responsibility Principle (SRP) in software architecture, is it considered good practice to create a single, massive
💻 Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Split Responsabilities pipeline. Include the setup and basic execution steps.
You are reviewing a Node Split Responsabilities pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
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.