Level 4 · Full-Stack Application Development · Course 4.3 Backend with Node.js
Module 45: Files and Logging
Goal: work with files on the server, accept uploads safely, and keep structured logs and error reports, so you can find out what happened when something goes wrong.
You'll need: your enquiries-api with sign-in from Module 44.
Lessons
- 1File operations15–25 minutes✓
- 2File uploads15–25 minutes✓
- 3Validating uploads15–25 minutes✓
- 4Structured logging15–25 minutes✓
- 5Error reports and monitoring15–25 minutes✓
🛠️Module practice: attachments and observability
- Safe file writes and a
safePathhelper. - Enquiry attachments: size and type limits checked by content, random names, signed-in downloads.
- Structured JSON logs with request ids, levels and redaction.
- Error reporting for unexpected errors; a health check; graceful shutdown.
- Nothing secret in logs. Commit.
✅Module check
Explain in a few sentences, in your own words:
How do you handle uploaded files safely, and how do you find out what went wrong in a running server?
Show a good answer
A good answer mentions: limit upload size and count, check type by content against a short allow-list, store files under generated names (ideally in object storage, with details in the database), never build paths from user input (path traversal), and serve files with safe headers after checking permission. To investigate problems: structured JSON logs with levels and request ids, without passwords, tokens or unnecessary personal data; error reporting with alerts for unexpected errors; health checks, uptime monitoring and graceful shutdown.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
