Complete the code to import the Express module.
const express = require('[1]');
The Express module is imported using require('express').
Complete the code to use multer middleware for file uploads.
const multer = require('[1]');
Multer is the middleware used for handling file uploads in Express.
Fix the error in the file filter function to only accept PNG files.
const fileFilter = (req, file, cb) => {
if (file.mimetype === '[1]') {
cb(null, true);
} else {
cb(null, false);
}
};The MIME type for PNG images is image/png. This filter allows only PNG files.
Fill both blanks to configure multer with a file size limit and file filter.
const upload = multer({
limits: { fileSize: [1] },
fileFilter: [2]
});The file size limit is set to 1MB (1024 * 1024 bytes). The fileFilter function is passed as the fileFilter option.
Fill all three blanks to create an Express route that uses multer to upload a single file named 'avatar'.
app.post('/upload', [1].single('[2]'), (req, res) => { if (!req.file) { return res.status(400).send('[3]'); } res.send('File uploaded successfully'); });
The multer instance is named upload. The single file field is named 'avatar'. The error message is 'No file uploaded'.