Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does storing files on disk mean in Express?
It means saving uploaded files directly to the server's hard drive or storage device. This keeps files persistent and accessible even after the server restarts.
Click to reveal answer
beginner
What is storing files in memory in Express?
It means keeping uploaded files temporarily in the server's RAM. Files are fast to access but lost when the server stops or restarts.
Click to reveal answer
beginner
Name one advantage of storing files on disk.
Files stay saved even if the server restarts, so data is not lost.
Click to reveal answer
beginner
Name one advantage of storing files in memory.
Accessing files is very fast because RAM is quicker than disk storage.
Click to reveal answer
beginner
What is a risk of storing files in memory?
If the server crashes or restarts, all files in memory are lost because RAM is temporary.
Click to reveal answer
Which storage method keeps files after server restarts?
AStoring files in memory
BStoring files on disk
CNeither
DBoth
✗ Incorrect
Files saved on disk remain after restarts; memory storage is temporary.
What is a benefit of storing files in memory?
AFaster access to files
BFiles are saved permanently
CFiles use less RAM
DFiles are encrypted automatically
✗ Incorrect
Memory storage allows faster file access because RAM is quicker than disk.
Which is a downside of storing files on disk?
AFiles are lost on server restart
BFiles cannot be accessed by Express
CAccess speed is slower than memory
DFiles use too much RAM
✗ Incorrect
Disk storage is slower to access compared to memory storage.
If you want to keep files only temporarily during a request, which storage is best?
AMemory storage
BDisk storage
CDatabase storage
DCloud storage
✗ Incorrect
Memory storage is good for temporary files during a request.
What happens to files stored in memory if the server crashes?
AFiles remain safe on disk
BFiles are backed up automatically
CFiles are sent to the client
DFiles are lost
✗ Incorrect
Files in memory are lost if the server crashes because RAM is volatile.
Explain the differences between storing files on disk and in memory in Express.
Think about speed and persistence.
You got /4 concepts.
When would you choose to store files in memory instead of on disk in an Express app?
Consider temporary file use cases.
You got /4 concepts.
Practice
(1/5)
1. In Express, what is the main difference between storing uploaded files on disk versus in memory?
easy
A. Disk storage is faster than memory storage for file uploads.
B. Disk storage saves files physically on the server, memory storage keeps files temporarily in RAM.
C. Memory storage saves files permanently, disk storage deletes files after upload.
D. Disk storage only works with images, memory storage only works with text files.
Solution
Step 1: Understand disk storage in Express
Disk storage saves uploaded files physically on the server's hard drive, making them persistent.
Step 2: Understand memory storage in Express
Memory storage keeps files temporarily in RAM, which is faster but not persistent after server restarts.
Final Answer:
Disk storage saves files physically on the server, memory storage keeps files temporarily in RAM. -> Option B
Quick Check:
Disk = physical, Memory = temporary RAM [OK]
Hint: Disk = saved on server, Memory = temporary RAM [OK]
Common Mistakes:
Thinking memory storage saves files permanently
Assuming disk storage is always faster
Confusing file types with storage methods
2. Which of the following is the correct way to configure multer for storing files in memory in Express?
easy
A. const upload = multer({ storage: multer.memoryStorage() });
B. const upload = multer({ storage: multer.diskStorage({}) });
C. const upload = multer({ dest: '/uploads' });
D. const upload = multer({ storage: 'memory' });
Solution
Step 1: Identify multer memory storage syntax
Memory storage is set by calling multer.memoryStorage() and passing it to the storage option.
What will be logged and sent if a 5000-byte file is uploaded?
medium
A. Throws an error because buffer is not available
B. Logs undefined, sends 'File size: undefined'
C. Logs 0, sends 'File size: 0'
D. Logs 5000, sends 'File size: 5000'
Solution
Step 1: Understand multer memoryStorage behavior
When using memoryStorage, the uploaded file is stored in req.file.buffer as a Buffer object containing the file data.
Step 2: Check properties used in code
req.file.buffer.length gives the byte length of the file buffer, which will be 5000 for a 5000-byte file. req.file.size also holds the file size in bytes.
Final Answer:
Logs 5000, sends 'File size: 5000' -> Option D
Quick Check:
Memory storage buffer length = file size [OK]
Hint: Memory storage files have buffer and size properties [OK]
Common Mistakes:
Assuming buffer is undefined in memoryStorage
Confusing size with buffer length
Expecting disk path properties in memory storage
4. You wrote this Express code to store files on disk: