Complete the code to import the Express framework.
const express = require('[1]');
We import the Express framework by requiring 'express'. This allows us to create an Express app.
Complete the code to set up middleware for handling file uploads using 'multer'.
const multer = require('[1]');
'multer' is a popular middleware to handle file uploads in Express apps.
Fix the error in the route to correctly handle a single file upload named 'avatar'.
app.post('/upload', upload.[1]('avatar'), (req, res) => { res.send('File uploaded!'); });
The 'single' method handles uploading one file with the given field name.
Fill both blanks to create a storage engine that saves files to the 'uploads/' folder with original filenames.
const storage = multer.diskStorage({
destination: (req, file, cb) => cb(null, '[1]'),
filename: (req, file, cb) => cb(null, file.[2])
});The destination folder is 'uploads/'. The filename uses the file's original name via 'originalname'.
Fill all three blanks to create an Express route that uses multer middleware with the storage engine and handles a single file upload named 'document'.
const upload = multer({ storage: [1] });
app.post('/submit', upload.[2]('[3]'), (req, res) => {
res.send('Upload complete');
});We pass the storage engine as 'storage' to multer. Then use 'single' to handle one file named 'document'.