šŸš€ 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 //

Passing the raw req/res objects into the Service layer instead of plain data

// Wrong: Service now depends on Express class UserService { static async register(req) { const { email } = req.body; /* ... */ } } // Correct: Service accepts plain data class UserService { static async register(email, password) { /* ... */ } } const user = await UserService.register(req.body.email, req.body.password);

The Solution //

A Service function that accepts req directly becomes impossible to call from anywhere except an Express route — a cron job, a CLI script, or a GraphQL resolver has no req object to hand it. Extract the specific values the service needs (email, password, an ID) in the Controller and pass those plain values, keeping the Service layer 100% HTTP-agnostic and reusable.

The Error //

Writing raw SQL or Mongoose queries directly inside a Service method

// Wrong: Service knows about raw SQL class UserService { static async register(email) { return db.query('INSERT INTO users (email) VALUES ($1)', [email]); } } // Correct: Service delegates to the Model class UserService { static async register(email) { return UserModel.create({ email }); } }

The Solution //

Once a Service starts calling db.query(...) directly instead of going through the Model layer, swapping databases or mocking data access in a unit test becomes impossible without touching every Service that has a query embedded in it. Route all persistence through Model methods (UserModel.findByEmail(), UserModel.create()) so the Service only ever talks to a stable, swappable data-access interface.

Continue Learning