A comprehensive backend API for a video hosting platform similar to YouTube, built with Node.js, Express.js, MongoDB, and more. This project implements all essential features for a modern video platform, including user authentication, video uploads, likes, comments, subscriptions, and more.
- User Authentication: Secure login/signup with JWT tokens (access and refresh tokens)
- Video Management: Upload, stream, and manage videos with Cloudinary integration
- User Interactions: Like/dislike videos, comments, replies, and subscriptions
- Dashboard: Analytics and user-specific data
- Rate Limiting: Protection against abuse with middleware
- File Uploads: Multer middleware for handling file uploads
- Health Checks: API health monitoring
- Docker Support: Containerized deployment for easy setup
- Comprehensive Testing: Integration and unit tests
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens), bcrypt for password hashing
- File Storage: Cloudinary for media uploads
- Middleware: Custom middlewares for auth, rate limiting, file uploads
- Testing: Mocha/Chai for API tests, database tests
- Containerization: Docker, Docker Compose
- Deployment: Render (production)
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- Docker (optional, for containerized setup)
- Cloudinary account for media storage
-
Clone the repository:
git clone https://github.com/your-username/videotube_backend.git cd videotube_backend -
Install dependencies:
npm install
-
Set up environment variables:
- Copy
sample.envto.env - Fill in the required values (see Environment Variables section below)
- Copy
-
Start MongoDB (if running locally):
mongod
-
Run the application:
npm start
For development with auto-restart:
npm run dev
-
Clone the repository:
git clone https://github.com/your-username/videotube_backend.git cd videotube_backend -
Set up environment variables:
- Create a
.envfile in the project root with the required variables (see below)
- Create a
-
Run with Docker:
docker run -it -p 3000:3000 --env-file .env coderdelta/videotube
Or using Docker Compose (if available):
docker-compose up
Create a .env file in the root directory with the following variables:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/videotube
CORS_ORIGIN=http://localhost:3000
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_secretOnce the server is running, you can access the API at http://localhost:3000 (or your configured port).
The API provides endpoints for:
- User management (register, login, profile)
- Video operations (upload, list, stream)
- Comments and replies
- Likes and dislikes
- Subscriptions
- Dashboard analytics
For detailed API documentation, import the Postman collection:
Run the test suite:
npm testThis includes:
- API integration tests
- Database connection tests
- Unit tests for utilities
videotube_backend/
├── src/
│ ├── app.js # Express app setup
│ ├── index.js # Server entry point
│ ├── constants.js # Application constants
│ ├── controllers/ # Route controllers
│ ├── db/ # Database connection
│ ├── middlewares/ # Custom middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ └── utils/ # Utility functions
├── test/ # Test files
├── public/temp/ # Temporary file storage
├── postman/ # Postman collections
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── package.json # Dependencies and scripts
└── README.md # This file
View the complete system architecture and database relationships:
The application is deployed on Render:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built following best practices for Node.js backend development
- Inspired by modern video platforms
- Uses industry-standard libraries and patterns