Node.js + Express API for the blog platform: posts, comments, auth (Firebase), Redis caching, Swagger docs.
- Runtime: Node.js 20
- Framework: Express
- DB: MongoDB (Mongoose)
- Auth: Firebase Admin (verify ID token); users synced to MongoDB on first request
- Cache: Redis (optional; app works without it)
- Docs: Swagger at
/api-docs
- Do not commit:
.env,.env.local,.env.vault,.env.keys, or any file containing real API keys, secrets, or passwords. These are in.gitignore; keep them that way. - Use
.env.exampleas a template only; never fill it with real values and commit.
-
Env
- Copy
.env.exampleto.env. - Set
MONGO_URIorMONGODB_URI,JWT_SECRET, and Firebase Admin vars (see.env.example). - Production CORS:
CORS_ALLOWED_ORIGINS=https://your-frontend-originorFRONTEND_URL=... - Optional:
REDIS_URL(defaultredis://localhost:6379).
- Copy
-
Run
- Local:
npm install && npm start(ornpm run dev). - With Docker:
docker-compose up(MongoDB + Redis + backend).
- Local:
- Base:
http://localhost:5000(or your deploy URL) - Docs:
GET /api-docs - Health:
GET /health(includesdb,redisstatus) - Metrics:
GET /metrics(request count, cache hits/misses, uptime) - Auth: Send Firebase ID token in header
x-auth-token
- Workflow:
.github/workflows/ci.ymlruns on push/PR tomainanddevelop. - Steps:
npm ci,npm run lint,npm test(Jest + Supertest with MongoDB and Redis services). - Tests: Auth is mocked; use
x-auth-tokenand optionallyx-test-uidfor non-owner tests.
So: Every push runs tests and lint; no manual-only testing.
| Decision | Reason |
|---|---|
| Firebase + Node | Firebase for auth; Node for blog data and ownership. Backend verifies token and syncs user to MongoDB. |
| Atlas vs local Mongo | Same code; use Atlas in production, local (or MongoMemoryServer in tests) for dev/CI. |
| Redis | Cache GETs for posts; TTL + invalidation on write. Optional: graceful degradation if Redis is down. |
| Security | Helmet, CORS allowlist, rate limiting, mongo-sanitize, xss-clean, HPP. |
- Live API: https://blog-backend-2-5hun.onrender.com
- Frontend: https://blog-frontend-sigma-ecru.vercel.app
Deployment checklist (Render): Set env vars in dashboard: MONGO_URI/MONGODB_URI, Firebase Admin vars, and CORS_ALLOWED_ORIGINS or FRONTEND_URL to your frontend origin. Never put secrets in code or in the repo.
See docs/IMPLEMENTATION_AUDIT.md for a full checklist of what’s implemented.