Bird
0
0

You want to limit the size of JSON request bodies to 100kb in Express. How do you configure express.json() middleware correctly?

hard📝 Application Q9 of 15
Node.js - HTTP Module
You want to limit the size of JSON request bodies to 100kb in Express. How do you configure express.json() middleware correctly?
Aapp.use(express.json({ limit: 100000 }));
Bapp.use(express.json({ sizeLimit: 100000 }));
Capp.use(express.json({ maxSize: '100kb' }));
Dapp.use(express.json({ limit: '100kb' }));
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct option name for size limit

    The option is limit and accepts string with units like '100kb'.
  2. Step 2: Check correct syntax for express.json()

    Use express.json({ limit: '100kb' }) to limit JSON body size.
  3. Final Answer:

    Use limit option with string '100kb' -> Option D
  4. Quick Check:

    Limit size option = limit: '100kb' = A [OK]
Quick Trick: Use limit: '100kb' string option to set body size limit [OK]
Common Mistakes:
  • Using wrong option names like sizeLimit or maxSize
  • Passing number instead of string with units
  • Omitting parentheses on middleware

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes