0
0
Expressframework~10 mins

File size limits in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the file size limit to 1MB using express.json().

Express
app.use(express.json({ limit: '[1]' }));
Drag options to blanks, or click blank then click option'
A1mb
B1024kb
C1000kb
D1MB
Attempts:
3 left
💡 Hint
Common Mistakes
Using '1024kb' (option B).
Using '1MB' (option D).
2fill in blank
medium

Complete the code to limit file uploads to 5MB using multer.

Express
const upload = multer({ limits: { fileSize: [1] } });
Drag options to blanks, or click blank then click option'
A5000000
B5 * 1024 * 1024
C5242880
D5e6
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of number bytes.
Using 5e6 which is close but not exact 5MB in bytes.
3fill in blank
hard

Fix the error in setting the file size limit for express.urlencoded().

Express
app.use(express.urlencoded({ extended: true, limit: '[1]' }));
Drag options to blanks, or click blank then click option'
A1024kb
B1MB
C1000000
D1mb
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric values instead of string with units.
Using lowercase 'mb' (option D).
4fill in blank
hard

Fill both blanks to set multer to accept files up to 2MB and only single file named 'avatar'.

Express
const upload = multer({ limits: { fileSize: [1] } });
app.post('/profile', upload.[2]('avatar'), (req, res) => { res.send('Uploaded'); });
Drag options to blanks, or click blank then click option'
A2097152
Bsingle
C2MB
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using '2MB' string instead of bytes number.
Using upload.array() instead of upload.single() for single file.
5fill in blank
hard

Fill all three blanks to create an express.json() middleware with 10MB limit, and multer to accept multiple files named 'photos' with 3 files max.

Express
app.use(express.json({ limit: '[1]' }));
const upload = multer({ limits: { fileSize: [2] } });
app.post('/upload', upload.[3]('photos', 3), (req, res) => { res.send('Files uploaded'); });
Drag options to blanks, or click blank then click option'
A10mb
B10485760
Carray
Dsingle
Attempts:
3 left
💡 Hint
Common Mistakes
Using '10MB' uppercase.
Using upload.single() instead of upload.array() for multiple files.