A small recommendation demo that uses a Node/Express backend with MongoDB and a React frontend. The backend serves simple user and post endpoints and implements a lightweight recommendation endpoint that prioritizes posts matching user interests and then popular posts.
-
backend/- Express server connecting to MongoDB. Key files:server.js- main server and API routespackage.json- backend dependencies
-
frontend/- Create React App frontend. Key files:package.json- frontend scripts and depsbuild/- production build output (already present)src/- React source (pages:home.js,feed.js,login.js)
- Node.js (16+ recommended)
- npm or yarn
- MongoDB running locally (default URI used:
mongodb://localhost:27017)
The backend is a minimal Express app. It expects a running MongoDB instance on mongodb://localhost:27017 and uses a database named recommend with two collections: users and posts.
Main endpoints (defined in backend/server.js):
-
POST /login
- Body: { username, password }
- Response: { status: "success", userId } or { status: "failed" }
-
POST /addPost
- Body: { userId, content, tags }
- Adds a post for the user. Returns { status: "success", postId }
-
POST /deletePost
- Body: { userId, postId }
- Deletes a post if it belongs to the user.
-
GET /feed
- Returns all posts
-
POST /like
- Body: { userId, postId }
- Toggles like/unlike. If liked, post.tags (if any) are added to the user's
interestsarray.
-
POST /recommend
- Body: { userId }
- Returns posts prioritized by user's interests (matching tags) sorted by like count, followed by other popular posts.
The server listens on port 5000 by default.
Start the backend:
cd backend
npm install
node server.js(You can also use a process manager like nodemon during development.)
The frontend is a Create React App project. Scripts are standard:
npm start- start dev servernpm run build- produce production build intofrontend/build
Start the frontend (development):
cd frontend
npm install
npm start- The backend uses a
userscollection. Users should have_id,username,password, and optionallyinterests(array of tags). - The
postscollection stores posts with fields:userId,user(username),content,tags(array),likes(array of userIds).
- No authentication/session management — the demo uses plain username/password checks and returns the user _id to represent an authenticated user.
- Passwords are stored in plaintext in this example (unsafe for production). Use hashing, HTTPS, and proper auth for real apps.
- No rate limiting, input validation, or robust error handling — suitable for demo and learning only.
- Add proper auth (JWT or sessions), password hashing
- Add input validation and error handling
- Add unit/integration tests
- Add environment-based configuration (use .env for MongoDB URI, ports)
- Add CORS restrictions and production-ready security hardening