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?
✗ Incorrect
The 'limit' option in express.json() sets the maximum size. '5mb' means 5 megabytes.
What middleware is best for handling file uploads with size limits in Express?
✗ Incorrect
'multer' is designed for handling multipart/form-data and file uploads with size limits.
How do you specify a 1MB file size limit in multer?
✗ Incorrect
The 'fileSize' property in 'limits' expects bytes, so 1 * 1024 * 1024 equals 1MB.
What error code does multer throw when a file exceeds the size limit?
✗ Incorrect
Multer uses the error code 'LIMIT_FILE_SIZE' for files exceeding the size limit.
Why is it important to set file size limits on uploads?
✗ Incorrect
File size limits help protect the server from overload and potential security issues.
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.