Bird
0
0

This Express code tries to parse JSON body but fails:

medium📝 Debug Q7 of 15
Node.js - HTTP Module
This Express code tries to parse JSON body but fails:
app.use(express.json);
app.post('/test', (req, res) => {
  res.json(req.body);
});

What is the error?
Aexpress.json middleware is not called as a function
Bres.json cannot send req.body
CRoute path must be '/test/' with trailing slash
Dexpress.json does not parse JSON bodies
Step-by-Step Solution
Solution:
  1. Step 1: Check middleware usage syntax

    Middleware must be called as a function: express.json(), not express.json.
  2. Step 2: Understand effect of missing parentheses

    Without calling, middleware is not applied, so req.body remains undefined.
  3. Final Answer:

    Missing parentheses causes middleware not to run -> Option A
  4. Quick Check:

    Middleware must be called with () = B [OK]
Quick Trick: Always call middleware functions with parentheses [OK]
Common Mistakes:
  • Forgetting parentheses on middleware
  • Thinking route path slash matters here
  • Assuming res.json can't send objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes