Project summary:
- Cinemetrics is a small movie SPA (single page app) built with native ES modules, Parcel bundler on the frontend, and an Express + MongoDB backend. It consumes TMDB and provides movie lists, trailers, and a simple JWT-based auth system (signup/login).
This README covers:
- System & software requirements
- Install steps
- Environment variables (.env) and required keys
- How to run the project locally (frontend + backend)
- Quick tests (signup/login + health checks)
- Files changed / features added during recent work
- Troubleshooting tips
1) Requirements (local dev machine)
- Node.js (v16+ recommended)
- npm (comes with Node)
- Internet access for TMDB images & API during dev
- MongoDB Atlas account (or local MongoDB) with a connection string
- Optional: Resend API key (for sending welcome emails) — not required to run server
2) Quick repo setup
- Clone the repo.
- Install dependencies:
npm install- Create a
.envfile in the project root (do not commit it). Example keys used by this app:
TMDB_API_KEY=<your_tmdb_api_key>
TMDB_ACCESS_TOKEN=<optional_tmdb_bearer_token>
MONGODB=<your_mongodb_connection_string>
JWT_SECRET=dev_secret_change_me
BACKEND_PORT=3000
RESEND_API_KEY=<optional_resend_api_key>
EMAIL_FROM=you@example.com
Notes:
- The app now prefers
BACKEND_PORTfor the backend port (soPORTwon't accidentally affect Parcel/frontend). Parcel is started with--port 1234inpackage.json. - Make sure
.envis listed in.gitignoreand do not push secrets.
3) Available npm scripts (see package.json)
npm run app:watch— start backend withnodemon(watchesserver/)npm run server— run server directly (node server/app.js)npm run devornpm start— start Parcel dev server for the frontend (explicitly set to port 1234)npm run build— build the frontend for production
Example to run both locally (open two terminals):
# terminal 1 — backend
npm run app:watch
# terminal 2 — frontend
npm run dev4) Quick API checks
- Backend health:
curl -i http://localhost:3000/status - Frontend root:
curl -I http://localhost:1234
5) Auth endpoints (examples)
Signup (creates a user):
curl -i -X POST http://localhost:3000/auth/signup \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"test@example.com","password":"secret"}'Login (returns JWT token):
curl -i -X POST http://localhost:3000/auth/login \
-H "Content-Type: application/json" \
-d '{"loginId":"testuser","password":"secret"}'Client-side (quick JS snippet) — paste into browser console to log in and save token:
(async () => {
const res = await fetch("http://localhost:3000/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ loginId: "you@example.com", password: "yourpass" }),
});
const data = await res.json();
if (res.ok) localStorage.setItem("token", data.token);
else console.error(data);
})();6) Changes implemented during this session
-
Backend: -
server/models/user.js— Mongoose user schema withusername,email,password, bcrypt hashing, andcomparePasswordhelper. Usernames/emails are saved lowercased. -server/controllers/auth.js—signupandloginhandlers implemented. Login now lowercases theloginIdbefore lookup to avoid case-sensitive misses. -server/routes/auth.js— mounted/auth/signupand/auth/loginroutes. -server/app.js— now prefersprocess.env.BACKEND_PORT || process.env.PORT || 3000for port selection. -
Frontend: -
views/login.jsandviews/signup.jscreated to render auth forms. -store/login.jsandstore/signup.jscreated (minimal state) to avoid import breakages. -components/nav.jsupdated to show login/signup or welcome/logout based onlocalStorage.token. -views/index.jsexports updated to includeloginandsignupso the router resolves/loginand/signup. -
CSS/layout fixes: - Fixed malformed CSS block that broke cascade (closed
.marvel-titleproperly). - Added defensive/grid overrides so.marvel-grid,.movies-grid,.movie-grid, and.releases-gridrender as CSS Grid and not horizontal flex when not desired. - Added.navbarand.nav-linksbase styles to enforce horizontal nav layout on desktop. - Increased.logo asize/weight (makes "Cinemetrics" prominent in nav bar). - Adjusted poster heights and.movie-cardlayout to make movie cards more proportional on Home / Movies pages. - Tightened.marvel-cardmin-height and.marvel-phase-rowspacing to reduce vertical gaps on the Marvel page. -.marvel-overviewnow wraps (overrideswhite-space: nowrap) so descriptions don't run in a single line.
7) Important tips / troubleshooting
-
Port conflict: If
3000or1234is already in use, free the ports or change ports. Example to free ports on Windows Git Bash:bash npx kill-port 3000 1234Or identify processes withnetstat -ano | findstr ":3000"and kill withtaskkill /PID <PID> /F. -
If the frontend shows a NotFound or blank page for
/login, confirmviews/index.jsexportsloginandsignupand that the router resolves the path. -
If signup returns success but login says
User not found, the cause was case mismatches — the login lookup was updated to perform a lowercase comparison. If problems persist, check server logs; they show meaningful errors (e.g., DB connection issues). -
RESEND_API_KEYwarning is informational — it only disables sending emails (welcome emails) and does not block signup/login. -
Database confirmations: use MongoDB Compass or shell to inspect the
userscollection:
use cinemetrics
db.users.find({}, { username:1, email:1, createdAt:1 }).pretty()8) Next suggestions / improvements
- Add client-side inline error messages for signup/login instead of alerts.
- Add form validation and stronger password policy.
- Add a simple profile view that decodes the JWT and shows the username.
- Implement logout server-side invalidation if needed (currently purely client-side clearing of
localStorage).
Possible additions:
- Add a small script to seed test users into the DB.
- Add a README section with screenshots and a small checklist for deployment (Netlify + Render) including environment variable mapping.
This README can be expanded with screenshots and exact file-by-file diffs as needed.
Troubleshooting & Lessons Learned
-
Initial problems encountered:
- Layout breaks: movie cards rendered horizontally and the nav stacked vertically due to malformed and cascading CSS rules.
- Malformed CSS: missing/extra braces and a
white-space: nowrapsomewhere caused descriptions not to wrap. - Port conflicts / dev server confusion: Parcel occasionally bound to the wrong port;
PORTenv collisions caused the frontend/backend to compete for3000. - Route NotFound for auth pages: client views like
loginandsignupweren't exported, causing the router to show NotFound. - Case-sensitive login lookup: DB saved
username/emaillowercased but login lookup was case-sensitive, causing "User not found" errors. - Missing local assets & MIME/CSP hiccups: attempts to self-host Font Awesome and other assets created transient build and MIME issues during experiments.
-
Workarounds and additions made to get things working:
- Defensive CSS fixes: corrected malformed blocks, added explicit grid rules for
.movies-grid,.marvel-grid,.movie-grid, and.releases-gridto stop unwanted horizontal flow. - Exported views: updated
views/index.jsto exportloginandsignupso routes resolve properly. - Normalized login: lowercased
loginIdinserver/controllers/auth.jsso lookups match stored lowercase emails/usernames. - Explicit backend port: added
BACKEND_PORTenvironment variable and madeserver/app.jsprefer it (process.env.BACKEND_PORT || process.env.PORT || 3000) so Parcel on1234and backend on3000don't collide. - Poster & card sizing: set poster heights and
object-fit: coverso cards remain proportional and consistent across breakpoints. - Port management tips: documented
npx kill-port 3000 1234andtaskkillcommands to free blocked ports quickly.
- Defensive CSS fixes: corrected malformed blocks, added explicit grid rules for
-
Lessons learned (project-level):
- Make the happy path explicit: prefer explicit ports and environment variable names so different tools don't accidentally steal the same port.
- Normalize data early: store and compare canonical forms (e.g., lowercase emails/usernames) to avoid case-sensitivity bugs.
- Protect CSS cascade: small syntax mistakes in CSS can break large parts of the UI; validate with the browser devtools and keep styles modular.
- Iterate & test incrementally: make small changes and verify locally before broad refactors — commit checkpoints frequently so you can revert experimental steps.
- Log everything: both frontend and backend logs helped track where requests were failing (e.g., which endpoint, what payload reached server).
-
Week-by-week incremental learning & applied changes
- Week 1 — Project scaffold & frontend: learned Parcel + native ES modules and basic app structure; scaffolded
index.html, entryindex.js, and a basic nav. Applied: initial routing and skeleton pages. - Week 2 — Backend & database: learned Mongoose basics and schema design; created
server/app.js,server/models/user.js, and connected to MongoDB. Applied: user schema with bcrypt hashing and a simple auth controller prototype. - Week 3 — TMDB integration: learned TMDB API basics and image paths; integrated poster fetching and basic movie list rendering. Applied: TMDB API calls in
services/api.jsand movie-list views. - Week 4 — Layout & styling polish: learned CSS Grid/Flex quirks and responsive techniques; fixed poster sizing and added defensive grid rules. Applied:
style.csscorrections,.marvel-overviewwrapping, and reduced card heights. - Week 5 — Auth UI + router fixes: learned client-side form handling and state flows; exported
login/signupviews and attached handlers to POST to backend. Applied: view exports, client auth handlers, andlocalStoragetoken save. - Week 6 — Dev ergonomics & reliability: learned to manage dev ports, environment variables, and server restart workflows. Applied:
BACKEND_PORTenv var, updatedpackage.jsonscripts for explicit ports, and documented port-kill tips. - Week 7 — Polishing & documentation: learned that documentation accelerates onboarding and debugging; started this README and captured lessons and troubleshooting steps. Applied: this
README.md(expanded), and CSS + auth bug fixes recorded above.
- Week 1 — Project scaffold & frontend: learned Parcel + native ES modules and basic app structure; scaffolded
-
Practical next steps (based on lessons):
- Add a
CONTRIBUTING.mdwith coding guidelines and a checklist for making safe CSS changes. - Add small unit/integration tests around
authhandlers (signup/login) so regressions are caught early. - Consider adding a small
seedscript to populate test users and example data for local dev.
- Add a