Which of the following best explains why handling file uploads properly in Express is crucial?
Think about what could happen if users upload very large or unsafe files.
Proper file upload handling helps avoid server crashes, security risks, and performance issues by controlling file size and type.
Consider an Express app that accepts file uploads without any size limit. What is the most likely outcome when a user uploads a very large file?
Think about how servers handle large amounts of data in memory.
Without size limits, large files can consume too much memory, causing crashes or slowdowns.
Choose the code that correctly configures Multer middleware to handle single file uploads named 'avatar'.
const express = require('express'); const multer = require('multer'); const app = express(); // Choose the correct Multer setup below
Look for correct Multer initialization and middleware usage for single file named 'avatar'.
Option D correctly initializes Multer with a destination folder and uses upload.single('avatar') to handle one file named 'avatar'.
Given this Express route using Multer, why does it throw an error when uploading a file?
const upload = multer({ dest: 'uploads/' });
app.post('/upload', (req, res) => {
upload.single('file')(req, res, (err) => {
if (err) {
return res.status(400).send('Upload error');
}
res.send('Upload complete');
});
});Check how Multer middleware should be applied in Express routes.
Multer's upload.single('file') must be passed as middleware to the route, not called inside the handler function.
After a user uploads a file using Multer's upload.single('photo') middleware, what does req.file contain?
Think about what information Multer provides for a single file upload.
Multer adds a req.file object containing metadata like filename, path, size, and mimetype for the uploaded file.