0
0
Expressframework~10 mins

Cloud storage integration concept in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Express framework.

Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Apath
Bhttp
Cexpress
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' to import the framework.
Forgetting to use quotes around the module name.
2fill in blank
medium

Complete the code to initialize the Express app.

Express
const app = [1]();
Drag options to blanks, or click blank then click option'
Aexpress
Brequire
Chttp
Drouter
Attempts:
3 left
💡 Hint
Common Mistakes
Calling http() instead of express().
Using require() without arguments.
3fill in blank
hard

Fix the error in the code to upload a file to AWS S3 using the AWS SDK.

Express
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);
});
Drag options to blanks, or click blank then click option'
A'file.txt'
Bfs.createReadStream('file.txt')
Cfs.readFileSync('file.txt')
DBuffer.from('file.txt')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the file name string instead of file content.
Using readFileSync which reads the whole file into memory.
4fill in blank
hard

Fill both blanks to configure Express to parse JSON and handle file uploads with multer.

Express
const express = require('express');
const multer = require('multer');
const upload = multer({ dest: '[1]' });

const app = express();
app.use(express.[2]());
Drag options to blanks, or click blank then click option'
Auploads/
Bjson
Curlencoded
Dpublic/
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'public/' instead of 'uploads/' for multer destination.
Using 'urlencoded' instead of 'json' for JSON parsing.
5fill in blank
hard

Fill all three blanks to create an Express POST route that uploads a single file named 'photo' and sends a success message.

Express
app.post('/upload', upload.[1]('[2]'), (req, res) => {
  if (!req.file) {
    return res.status(400).send('[3]');
  }
  res.send('File uploaded successfully');
});
Drag options to blanks, or click blank then click option'
Asingle
Barray
Cphoto
DNo file uploaded
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' instead of 'single' for one file upload.
Checking wrong request property for the file.
Sending a generic error message instead of 'No file uploaded'.