Performance: Why file upload handling matters
HIGH IMPACT
File upload handling affects server response time and client perceived loading speed during file transfers.
import multer from 'multer'; const upload = multer({ dest: 'uploads/' }); app.post('/upload', upload.single('file'), (req, res) => { res.send('Upload complete'); });
app.post('/upload', (req, res) => { let data = ''; req.on('data', chunk => { data += chunk; }); req.on('end', () => { // process entire file in memory saveFile(data); res.send('Upload complete'); }); });
| Pattern | Memory Usage | Event Loop Blocking | Server Response Time | Verdict |
|---|---|---|---|---|
| Manual data buffering in memory | High (entire file in RAM) | Yes (blocks event loop) | Slow for large files | [X] Bad |
| Streaming upload with multer middleware | Low (streams to disk) | No (non-blocking) | Fast and scalable | [OK] Good |