A simple full‑stack blog demo with a Node/Express backend and a Next.js frontend.
backend/— Express API, MongoDB models, middleware for auth and image upload(Cloudinary)frontend/— Next.js (app router) frontend with pages, components and client API helpers.
Key backend files:
backend/server.js— main server entry.backend/src/models/— Mongoose models (User,BlogPost).backend/src/routes/— API routes (authRoutes.js,blogRoutes.js).backend/.env.example— example environment variables required by the backend.
Key frontend files:
frontend/src/app/— Next.js app pages and admin area.frontend/src/components/— UI components.frontend/src/lib/api.jsandfrontend/src/lib/secureApi.js— client API helpers.frontend/.env— environment variables for the frontend (e.g.NEXT_PUBLIC_API_URL).
- Node.js (recommend v18 or later)
- npm (bundled with Node) or yarn
- MongoDB database (Atlas)
- A Cloudinary account for image uploads
Backend: copy backend/.env.example to backend/.env and update values. Example keys found in the project:
CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>
JWT_SECRET=your_jwt_secret_here
MONGO_URI=mongodb+srv://<user>:<password>@your-cluster.mongodb.net/<dbname>
Frontend: frontend/.env currently contains:
NEXT_PUBLIC_API_URL=http://localhost:5000
Adjust NEXT_PUBLIC_API_URL to point to your running backend API.
Open two terminals (one for backend, one for frontend):
Backend (from repo root):
cd backend
npm install
# create .env from example and edit values
cp .env.example .env
# start dev server (uses nodemon)
npm run devNotes:
npm run devinbackendrunsnodemon server.js.npm.startwill runnode server.js(for production/startup without nodemon).
Frontend:
cd frontend
npm install
npm run devThe frontend runs on http://localhost:3000 by default. It uses NEXT_PUBLIC_API_URL to talk to the backend.
Import project repo to vercel and deploy the frontend and backend separately using the required environment variables.
- If uploads fail, confirm
CLOUDINARY_URLis set and valid. - Check backend logs for MongoDB connection errors; ensure
MONGO_URIis reachable.
- Authentication logic:
backend/src/middleware/authMiddleware.jsandbackend/src/routes/authRoutes.js. - Cloudinary uploads:
backend/src/middleware/cloudinaryMiddleware.jsand usage in routes. - Client API usage:
frontend/src/lib/api.jsandfrontend/src/lib/secureApi.js.