Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Under the architectural principle of
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Building Backend Systems pipeline. Include the setup and basic execution steps.
You are reviewing a Node Building Backend Systems 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 //
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.