0
0
Expressframework~20 mins

Storing files on disk vs memory in Express - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Storage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding file storage behavior in Express with multer
Consider an Express app using multer middleware to handle file uploads. If multer is configured with storage: multer.memoryStorage(), what happens to the uploaded file data?
Express
const multer = require('multer');
const upload = multer({ storage: multer.memoryStorage() });

app.post('/upload', upload.single('file'), (req, res) => {
  console.log(req.file.buffer);
  res.send('File received');
});
AThe file is streamed directly to a cloud storage service without local storage.
BThe file is saved directly to disk in a temporary folder and req.file.path contains the file path.
CThe file is stored temporarily in RAM as a Buffer accessible via req.file.buffer.
DThe file is discarded immediately and not accessible in the request handler.
Attempts:
2 left
💡 Hint
Think about where memoryStorage keeps the file data.
component_behavior
intermediate
2:00remaining
Behavior of multer.diskStorage in Express
When multer is configured with storage: multer.diskStorage(), what is true about the uploaded files?
Express
const multer = require('multer');
const storage = multer.diskStorage({
  destination: (req, file, cb) => cb(null, './uploads'),
  filename: (req, file, cb) => cb(null, file.originalname)
});
const upload = multer({ storage });

app.post('/upload', upload.single('file'), (req, res) => {
  console.log(req.file.path);
  res.send('File saved to disk');
});
AThe file is converted to a base64 string and stored in req.file.base64.
BThe file is stored in memory and req.file.buffer contains the data.
CThe file is uploaded but not saved anywhere automatically.
DThe file is saved to the specified disk folder and req.file.path contains the file path.
Attempts:
2 left
💡 Hint
Disk storage means saving files on your server's hard drive.
📝 Syntax
advanced
2:00remaining
Identifying error in multer memoryStorage usage
Which option will cause a runtime error when trying to access the uploaded file's data in an Express route using multer with memoryStorage?
Express
const multer = require('multer');
const upload = multer({ storage: multer.memoryStorage() });

app.post('/upload', upload.single('file'), (req, res) => {
  // Access file data here
});
Aconsole.log(req.file.path.length);
Bconsole.log(req.file.buffer.toString('utf8'));
Cconsole.log(req.file.size);
Dconsole.log(req.file.mimetype);
Attempts:
2 left
💡 Hint
memoryStorage does not save files on disk, so some properties are missing.
state_output
advanced
2:00remaining
Comparing memory usage between diskStorage and memoryStorage
In an Express app handling large file uploads, what is a key difference in server memory usage between multer's diskStorage and memoryStorage?
ABoth use the same amount of RAM because multer buffers files in memory regardless of storage type.
BmemoryStorage uses more RAM because files are kept in memory; diskStorage uses less RAM but uses disk space.
CdiskStorage uses more RAM because it buffers files before saving; memoryStorage writes directly to disk.
DmemoryStorage uses less RAM because it streams files directly to disk.
Attempts:
2 left
💡 Hint
Think about where the file data lives during upload.
🔧 Debug
expert
2:00remaining
Debugging file upload failure with multer diskStorage
An Express app uses multer.diskStorage to save uploaded files to './uploads'. However, uploads fail silently and no files appear in the folder. What is the most likely cause?
AThe './uploads' folder does not exist or lacks write permissions.
BThe Express app is missing the body-parser middleware.
CThe file input field name in the HTML form does not match the multer field name.
DThe multer middleware is missing the .single() or .array() method call.
Attempts:
2 left
💡 Hint
Check if the folder exists and can be written to by the server.