Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
If a frontend sends a POST request with a JSON payload to your Express server, but `req.body` is completely undefined, what did you most likely forget to register?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Express.js (router, middleware) pipeline. Include the setup and basic execution steps.
You are reviewing a Node Express.js (router, middleware) 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 //
req.body is undefined because express.json() was registered after the routes
// Wrong: route registered before the parser
app.post('/users', (req, res) => res.json(req.body)); // undefined
app.use(express.json());
// Correct: parser first
app.use(express.json());
app.post('/users', (req, res) => res.json(req.body));The Solution //
Express middleware only affects requests that reach it, in registration order. If app.use(express.json()) is placed after app.post('/users', ...), the JSON body parser never runs before that route's handler, so req.body is undefined. Always register body-parsing middleware before any routes that need to read req.body.
The Error //
A custom error-handling middleware is silently never called
// Wrong: only 3 params, Express treats it as regular middleware
app.use((req, res, next) => { /* never runs on errors */ });
// Correct: exactly 4 params marks it as an error handler
app.use((err, req, res, next) => {
res.status(500).json({ error: err.message });
});The Solution //
Express identifies error-handling middleware specifically by its function arity ā it must declare exactly four parameters: (err, req, res, next). A handler written with only three params ((req, res, next)) is treated as regular middleware and Express skips it entirely when next(error) is called, letting errors fall through to the default handler instead.