A production-ready, scalable video hosting & streaming REST API built with Node.js, Express, and MongoDB.
VideoTube is a backend service powering video streaming, content distribution, and social interactions (likes, comments, subscriptions, playlists, and user profiles). Designed with clean architecture, enterprise error handling, and secure authentication workflows.
- 🔐 Dual-Token Authentication — Secure user access with short-lived JWT Access Tokens & long-lived Refresh Tokens.
- ☁️ Cloud Media Pipeline — Multipart form handling with Multer and automated asset optimization & upload via Cloudinary.
- 🛡️ Standardized API Standard — Uniform response structures (
ApiResponse) and centralized error handling (ApiError). - ⚡ Mongoose Aggregation Pipelines — High-performance pagination, watch history tracking, and channel subscription metrics.
- 🔒 Secure by Design — Passwords hashed with Bcrypt, CORS configured for granular origin control, and HTTP-only cookie support.
flowchart LR
Client([Client / Postman]) -->|Request + Multipart Data| Multer[Multer Temp Storage]
Multer --> Controller[Controller Layer]
Controller -->|Upload Assets| Cloudinary[(Cloudinary CDN)]
Controller -->|Store Metadata| MongoDB[(MongoDB Atlas)]
Controller -->|Uniform Response| ApiResponse[ApiResponse / ApiError]
ApiResponse --> Client
src/
├── controllers/ # Request handlers & core business logic
├── db/ # Database connection & lifecycle management
├── middlewares/ # Multer, Auth guards, validation middlewares
├── models/ # Mongoose schemas & custom methods
├── routes/ # RESTful API route definitions
└── utils/ # Async wrappers, ApiError, ApiResponse, Cloudinary
git clone https://github.com/Divyanshu0902/VideoTube.git
cd VideoTube
npm installCreate a .env file in the root directory:
PORT=8000
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net
CORS_ORIGIN=*
# JWT Secrets
ACCESS_TOKEN_SECRET=your_access_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your_refresh_token_secret
REFRESH_TOKEN_EXPIRY=10d
# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secretnpm run devServer will start listening on http://localhost:8000.
Divyanshu Kumar
- GitHub: @Divyanshu0902
Built with ❤️ for scalable media streaming architectures.
