A Node.js backend API for a video hosting platform, modeled after YouTube. Supports user authentication, profile management, media uploads via Cloudinary, and core social features such as subscriptions. Built with Express, MongoDB, and JWT-based security.
- User registration and login with email or username
- Secure password hashing (bcrypt)
- Access and refresh token authentication (JWT)
- Protected routes with middleware
- Avatar and cover image upload (Multer + Cloudinary)
- Account details update and password change
- Token refresh and logout
- Subscription model (subscriber/channel relationship)
- Video model with aggregation pagination support
- Standardized API responses and error handling
- Runtime: Node.js (ES Modules)
- Framework: Express 5
- Database: MongoDB with Mongoose
- Authentication: JWT + bcrypt
- File Upload: Multer + Cloudinary
- Other: cookie-parser, cors, dotenv, mongoose-aggregate-paginate-v2
- Node.js >= 18
- MongoDB instance (local or Atlas)
- Cloudinary account
git clone https://github.com/SupriyoP09/VideoTube.git
cd VideoTube
npm installCreate a .env file in the root directory:
PORT=8000
MONGODB_URI=
CORS_ORIGIN=
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=10d
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
npm run devThe server starts on the port defined in .env (default 8000).
Base path: /api/v1/user
| Method | Endpoint | Auth Required | Description |
|---|---|---|---|
| POST | /register | No | Register a new user |
| POST | /login | No | Login and receive tokens |
| POST | /logout | Yes | Logout and clear cookies |
| POST | /refresh-token | No | Refresh access token |
Additional controller methods exist for password change, current user retrieval, and profile/image updates. These can be wired to routes as needed.
src/
├── app.js # Express app setup and middleware
├── index.js # Entry point and DB connection
├── constants.js # Application constants
├── controllers/ # Route handlers
├── db/ # Database connection
├── middlewares/ # Auth and Multer middleware
├── models/ # Mongoose schemas (User, Video, Subscription)
├── routes/ # API route definitions
└── utils/ # ApiError, ApiResponse, asyncHandler, Cloudinary helper
public/
└── temp/ # Temporary upload directory
- Avatar is required on registration; cover image is optional.
- Refresh tokens are stored in the database and validated on refresh.
- Temporary files are cleaned after successful or failed Cloudinary uploads.
- The Video and Subscription models are defined and ready for expansion.