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

A Controller reaches directly into the database instead of going through the Service/Model layers

// Wrong: controller talks to the DB directly app.post('/checkout', async (req, res) => { const rows = await db.query('SELECT * FROM carts WHERE id = $1', [req.body.cartId]); res.json(rows); }); // Correct: controller delegates to a service app.post('/checkout', async (req, res) => { const result = await CheckoutService.process(req.body.cartId); res.json(result); });

The Solution //

Once a controller starts running its own SQL or ORM queries 'just this once for speed,' the boundary erodes fast — soon business logic, validation, and data access are all tangled inside route handlers again, and nothing is unit-testable without a live database. Route all data access through the Service layer, and keep the Controller responsible only for parsing the request and shaping the HTTP response.

The Error //

Hardcoding environment-specific values (DB URLs, API keys, ports) directly in application code

// Wrong: scattered and environment-specific mongoose.connect('mongodb://localhost:27017/app'); // Correct: one source of truth // config/env.js export const config = { dbUri: process.env.DATABASE_URL, port: process.env.PORT || 3000 };

The Solution //

A connection string or Stripe key written straight into a controller or model works fine locally but breaks the moment the same code runs in staging or production, and it risks committing secrets to version control. Centralize every environment-dependent value in a config module that reads from process.env, so switching environments never requires touching business logic.

Continue Learning