Node.js · Senior · Question 19 of 75
How should a server limit the size of incoming request bodies?
- ✓Correct answer: Set a body size limit in the parser (e.g.
express.json({ limit: "100kb" })) and reject larger requests early with 413 - 2Node.js limits bodies to 1 KB automatically
- 3Read the whole body into memory, then check its size
Explanation
Without limits, a client can exhaust memory with one huge request. Stream large uploads to storage instead of buffering them.