Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
In a 3-Tier Layered Architecture, which layer is responsible for extracting the JSON payload from the incoming HTTP `req.body` and formatting the outgoing `res.json()` response?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Layers Architecture (controllers, services, models) pipeline. Include the setup and basic execution steps.
You are reviewing a Node Layers Architecture (controllers, services, models) 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 //
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.