Profiles and Media
Goal
This snapshot advances Copperline Journal by teaching you to show author profiles and accept constrained avatar uploads.
Every numbered folder is a complete app. Run this stage independently, then compare it with the previous folder to see the new responsibility clearly.
Prerequisites
Use Node.js 20 or newer, npm, and a terminal. You should recognize basic JavaScript functions, objects, and HTTP requests.
Port 3000 must be available. MongoDB snapshots use Docker locally; copy the example environment file before starting them.
- Node.js and npm installed
- A code editor and terminal
- Docker from part 4 onward
Concepts
Multer parses multipart forms. Safe media handling uses generated filenames, size limits, MIME checks, and a default image.
Keep responsibilities visible: middleware prepares requests, routes choose handlers, models protect data rules, and EJS views present escaped values.
Walkthrough
Protect profile editing, allowlist display name and bio, accept image uploads, and show profile pages with each author's posts.
Read the example from input to output, then inspect the matching snapshot. The repository includes the surrounding setup and error handling.
const upload = multer({ limits: { fileSize: 2 * 1024 * 1024 }, fileFilter });
app.post("/profile/edit", ensureAuth, upload.single("image"), updateProfile);
Run and verify
Enter 08-Profiles-And-Media, install its dependencies, copy .env.example when present, and start the server.
Open http://localhost:3000. Keep the terminal visible so route, validation, and database errors can be connected to the browser action that caused them.
docker compose up -d
git clone https://github.com/michaeldunga1/fcc-express-blog.git
cd fcc-express-blog/08-Profiles-And-Media
npm install
cp .env.example .env
npm start
# optional: npm run seed
Troubleshooting
If no file arrives, check multipart form encoding and the field name. Local uploads on Render are ephemeral.
A missing-module error usually means npm install ran in another snapshot. For database failures, check the container and that this folder uses its own Copperline database name.
- Read the first error first
- Restart after environment changes
- Never commit .env or node_modules
Try this
Upload a valid image, then confirm a text file and oversized image are rejected.
Test a happy path and one invalid or unauthorized request. Useful applications return clear feedback without exposing secrets or stack traces.
- Make one small change
- Test it in the browser
- Compare with the next snapshot only after it works
Next: Posts CRUD and Ownership
Comments
One comment per signed-in account. Comments are saved with this page’s URL.