Challenge - 5 Problems
File Size Limits Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a file larger than the limit is uploaded?
Consider an Express app using the
express.json() middleware with a file size limit set to 1MB. What will happen if a client uploads a JSON payload of 2MB?Express
const express = require('express'); const app = express(); app.use(express.json({ limit: '1mb' })); app.post('/upload', (req, res) => { res.send('Upload successful'); });
Attempts:
2 left
💡 Hint
Think about how Express middleware handles payloads exceeding the set limit.
✗ Incorrect
Express's built-in body parsers like express.json() enforce the size limit and respond with a 413 error if the payload is too large.
📝 Syntax
intermediate2:00remaining
Which option correctly sets a 5MB file size limit for JSON payloads?
Choose the correct way to configure Express's JSON parser to accept payloads up to 5 megabytes.
Attempts:
2 left
💡 Hint
Check the official option name and format for size limits in Express.
✗ Incorrect
The correct option is 'limit' with a string value like '5mb'. Other option names or formats are invalid.
🔧 Debug
advanced2:00remaining
Why does this Express app not enforce the file size limit?
Given the code below, why does the server accept payloads larger than 1MB without error?
Express
const express = require('express'); const app = express(); app.use(express.urlencoded({ extended: true })); app.use(express.json()); app.post('/data', (req, res) => { res.send('Received'); });
Attempts:
2 left
💡 Hint
Look at the middleware configuration for express.json().
✗ Incorrect
Without specifying the 'limit' option, express.json() uses the default limit which is quite large, effectively allowing big payloads.
🧠 Conceptual
advanced2:00remaining
How does Express handle file uploads exceeding the limit with multer?
When using multer middleware to handle file uploads with a size limit set, what happens if a user uploads a file larger than the limit?
Attempts:
2 left
💡 Hint
Think about how multer signals errors for file size violations.
✗ Incorrect
Multer emits a MulterError with code 'LIMIT_FILE_SIZE' when the uploaded file exceeds the configured size limit and prevents saving the file.
❓ state_output
expert2:00remaining
What is the value of req.file after a too-large file upload with multer?
In an Express route using multer with a 1MB file size limit, a user uploads a 2MB file. What will be the value of
req.file inside the route handler?Express
const multer = require('multer'); const upload = multer({ limits: { fileSize: 1 * 1024 * 1024 } }); app.post('/upload', upload.single('file'), (req, res) => { res.json({ file: req.file }); });
Attempts:
2 left
💡 Hint
Consider multer's behavior when a file exceeds the size limit.
✗ Incorrect
When multer rejects a file due to size, it does not set req.file, so req.file remains undefined.