0
0
Expressframework~5 mins

File size limits in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of setting file size limits in Express file uploads?
File size limits prevent users from uploading files that are too large, which helps protect the server from running out of memory or disk space and improves security.
Click to reveal answer
beginner
How do you set a file size limit using the 'express.json()' middleware?
You set the 'limit' option in 'express.json()', for example: app.use(express.json({ limit: '1mb' })) to limit JSON payloads to 1 megabyte.
Click to reveal answer
intermediate
Which middleware is commonly used in Express to handle file uploads with size limits?
The 'multer' middleware is commonly used to handle file uploads and allows setting file size limits using the 'limits' option.
Click to reveal answer
intermediate
How do you configure 'multer' to reject files larger than 2MB?
You pass a 'limits' object when creating the multer instance: <code>const upload = multer({ limits: { fileSize: 2 * 1024 * 1024 } })</code>. This rejects files bigger than 2 megabytes.
Click to reveal answer
intermediate
What happens if a user tries to upload a file larger than the set limit in Express with multer?
Multer throws an error with code 'LIMIT_FILE_SIZE'. You can catch this error in your route handler to send a friendly message to the user.
Click to reveal answer
Which option correctly sets a 5MB limit for JSON payloads in Express?
Aapp.use(express.json({ sizeLimit: 5000 }))
Bapp.use(express.json({ maxSize: 5 }))
Capp.use(express.json({ limit: '5mb' }))
Dapp.use(express.json({ maxPayload: '5MB' }))
What middleware is best for handling file uploads with size limits in Express?
Amulter
Bhelmet
Ccors
Dbody-parser
How do you specify a 1MB file size limit in multer?
AmaxSize: 1024
Blimits: { maxFileSize: 1 }
Climit: '1mb'
Dlimits: { fileSize: 1 * 1024 * 1024 }
What error code does multer throw when a file exceeds the size limit?
ALIMIT_FILE_SIZE
BFILE_TOO_LARGE
CSIZE_EXCEEDED
DUPLOAD_ERROR
Why is it important to set file size limits on uploads?
ATo speed up the upload process
BTo prevent server overload and security risks
CTo allow unlimited file uploads
DTo reduce the number of users
Explain how to set and handle file size limits in Express using multer.
Think about configuring multer and catching errors.
You got /3 concepts.
    Describe why setting file size limits is important in web applications.
    Consider server health and user experience.
    You got /3 concepts.