Node.js/Express backend for Reel-Food: a short-form food video platform with user accounts, food partner accounts, likes, saves, and media uploads via ImageKit.
- Runtime: Node.js (ES Modules)
- Framework: Express
- Database: MongoDB with Mongoose
- Auth: JWT (httpOnly cookie)
- Security/Utils: bcryptjs, cookie-parser, cors, dotenv
- Uploads: multer (memoryStorage) + ImageKit SDK
backend/
server.js
package.json
src/
app.js
db/db.js
controllers/
auth.controller.js
food.controller.js
food-partner.controller.js
middlewares/
auth.middleware.js
multer.middleware.js
models/
user.model.js
food.model.js
likes.model.js
saved.model.js
foodpartner.model.js
routes/
auth.route.js
food.route.js
food-partner.route.js
services/
storage.service.js
- Prerequisites
- Node.js 18+ and npm
- MongoDB instance and credentials
- ImageKit account (for media uploads)
- Install dependencies
npm install- Environment variables
Create a
.envfile inbackend/with:
PORT=3000
CLIENT_URL=frontend_url
# MongoDB
DB_URI=mongodb_url
DB_NAME=db_name
# Auth
JWT_SECRET=replace-with-a-strong-secret
# ImageKit
IMAGEKIT_PUBLIC_KEY=your_public_key
IMAGEKIT_PRIVATE_KEY=your_private_key
IMAGEKIT_URL_ENDPOINT=imagekit_url- Run the server (with nodemon)
npm startServer starts at http://localhost:3000. Health check: GET / -> { success: true, message: "API is working" }.
npm start: Runnodemon server.js
Base URL: http://localhost:3000
-
Root
GET /→ API health
-
Auth (
/api/auth)POST /user/register→ Register user{ fullName, email, password }POST /user/login→ Login user{ email, password }(setstokencookie)GET /user/logout→ Logout user (clears cookie)POST /food-partner/register→ Register partner{ name, email, password, phone, address, contactName }POST /food-partner/login→ Login partner{ email, password }(setstokencookie)GET /food-partner/logout→ Logout partner
-
Food (
/api/food)GET /→ List food itemsPOST /add-food→ Create food (partner auth required)- multipart/form-data fields:
video(file, required),name(string),description(string)
- multipart/form-data fields:
POST /like→ Toggle like on a food (user auth required){ foodId }POST /save→ Toggle save on a food (user auth required){ foodId }GET /save→ Get saved foods for the current user (user auth required)
-
Food Partner (
/api/food-partner)GET /:id→ Get food partner profile plus their food items (user auth required)
Notes:
- Auth middleware reads JWT from
tokenhttpOnly cookie. Cookies are set withsecure: trueandsameSite: "None"; use HTTPS or appropriate dev tooling.
User:fullName,email(unique),password(select: false)FoodPartner:name,contactName,phone(unique),address,email(unique),password(select: false)Food:name,video,description?,foodPartner(ref),likeCount,saveCountLike:user(ref),food(ref)Save:user(ref),food(ref)
- CORS:
originis set fromCLIENT_URL;credentials: trueis enabled. - Uploads:
multer.memoryStorage()buffers the file andImageKit.upload()stores it; store your keys in.env. - DB:
mongoose.connect(DB_URI, { dbName: DB_NAME }).