Complete the code to import the Express framework.
const express = require('[1]');
The Express framework is imported using require('express').
Complete the code to initialize the Express app.
const app = [1]();http() instead of express().require() without arguments.To create an Express app, call express().
Fix the error in the code to upload a file to AWS S3 using the AWS SDK.
const AWS = require('aws-sdk'); const fs = require('fs'); const s3 = new AWS.S3(); const params = { Bucket: 'my-bucket', Key: 'file.txt', Body: [1] }; s3.upload(params, (err, data) => { if (err) console.log(err); else console.log('Upload success:', data.Location); });
readFileSync which reads the whole file into memory.To upload a file stream to S3, use fs.createReadStream('file.txt') as the Body.
Fill both blanks to configure Express to parse JSON and handle file uploads with multer.
const express = require('express'); const multer = require('multer'); const upload = multer({ dest: '[1]' }); const app = express(); app.use(express.[2]());
Set multer's destination folder to 'uploads/' and use express.json() middleware to parse JSON bodies.
Fill all three blanks to create an Express POST route that uploads a single file named 'photo' and sends a success message.
app.post('/upload', upload.[1]('[2]'), (req, res) => { if (!req.file) { return res.status(400).send('[3]'); } res.send('File uploaded successfully'); });
Use upload.single('photo') to handle one file named 'photo'. Send 'No file uploaded' if missing.