Bird
0
0

Which of the following is the correct way to add JSON body parsing middleware in an Express app?

easy📝 Syntax Q3 of 15
Node.js - HTTP Module
Which of the following is the correct way to add JSON body parsing middleware in an Express app?
Aapp.use(bodyParser.json);
Bapp.use(express.urlencoded);
Capp.use(express.json());
Dapp.use(express.static('json'));
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct syntax for middleware usage

    Middleware functions must be called, so parentheses are required.
  2. Step 2: Identify the correct middleware for JSON parsing

    express.json() is the built-in middleware for JSON parsing.
  3. Final Answer:

    Use app.use(express.json()); with parentheses -> Option C
  4. Quick Check:

    Correct middleware call syntax = B [OK]
Quick Trick: Always call middleware functions with parentheses [OK]
Common Mistakes:
  • Forgetting parentheses when adding middleware
  • Using deprecated bodyParser.json without calling it
  • Confusing urlencoded with json middleware

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes