This project serves as the backend for a Video Platform similar to Youtube. It provides APIs for user authentication, video management, user profiles, subscriptions, and more.
- Node.js: JavaScript runtime environment
- Express.js: Web application framework for Node.js
- MongoDB: NoSQL database for storing application data
- Mongoose: ODM (Object Data Modeling) library for MongoDB and Node.js
- JWT (JSON Web Tokens): For user authentication and authorization
- bcrypt: Library for hashing passwords
- Cloudinary: Cloud-based image and video management platform
- Multer: Middleware for handling file uploads in Node.js
- dotenv: Module for loading environment variables from a .env file
- cors: Middleware for enabling CORS (Cross-Origin Resource Sharing)
- cookie-parser: Middleware for parsing cookies in Express
-
Clone the repository:
git clone https://github.com/Vtsl-patel/videoBackend.git cd youtubeBackend
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory with the following variables:PORT=3000 MONGODB_URI=mongodb://localhost:27017/youtube_clone ACCESS_TOKEN_SECRET=your_access_token_secret REFRESH_TOKEN_SECRET=your_refresh_token_secret CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key CLOUDINARY_API_SECRET=your_cloudinary_api_secret
-
Start the server:
npm run dev
POST /register
- Register a new userPOST /login
- Login an existing userPOST /logout
- Logout the currently logged-in userPOST /refresh-token
- Refresh access token using refresh tokenPOST /change-password
- Change the current user's passwordGET /current-user
- Get details of the current userPATCH /update-account
- Update account details (full name, email)PATCH /avatar
- Update user avatarPATCH /cover-image
- Update user cover imageGET /channel/:username
- Get profile details of a user's channelGET /history
- Get watch history of the current user
GET /videos
- Get all videosPOST /videos
- Publish a video (includes video file and thumbnail upload)GET /videos/:videoId
- Get a video by IDDELETE /videos/:videoId
- Delete a videoPATCH /videos/:videoId
- Update a video (includes thumbnail upload)PATCH /videos/toggle/publish/:videoId
- Toggle publish status of a video
POST /playlists
- Create a playlistGET /playlists/:playlistId
- Get a playlist by IDPATCH /playlists/:playlistId
- Update a playlistDELETE /playlists/:playlistId
- Delete a playlistPATCH /playlists/add/:videoId/:playlistId
- Add a video to a playlistPATCH /playlists/remove/:videoId/:playlistId
- Remove a video from a playlistGET /playlists/user/:userId
- Get playlists of a user
GET /subscriptions/c/:channelId
- Get subscribed channelsPOST /subscriptions/c/:channelId
- Toggle subscription statusGET /subscriptions/u/:channelId
- Get subscribers of a user channel
POST /likes/toggle/v/:videoId
- Toggle like status on a videoPOST /likes/toggle/c/:commentId
- Toggle like status on a commentPOST /likes/toggle/t/:tweetId
- Toggle like status on a tweetGET /likes/videos
- Get liked videos
GET /comments/:videoId
- Get comments for a videoPOST /comments/:videoId
- Add a comment to a videoDELETE /comments/c/:commentId
- Delete a commentPATCH /comments/c/:commentId
- Update a comment
POST /tweets
- Create a tweetGET /tweets/user/:userId
- Get tweets of a userPATCH /tweets/:tweetId
- Update a tweetDELETE /tweets/:tweetId
- Delete a tweet
GET /dashboard/stats
- Get channel statisticsGET /dashboard/videos
- Get videos of the channel
The backend of the YouTube clone is organized into multiple controllers, each managing specific aspects of the application to ensure a seamless user experience.
- User Controller: Handles user authentication, profile management, and avatar/cover image updates. It leverages robust libraries and services such as JWT for token management, bcrypt for password hashing, Cloudinary for image management, and MongoDB for data storage.
- Comment Controller: Manages commenting functionality, allowing users to add, update, and delete comments on videos.
- Dashboard Controller: Provides endpoints for retrieving channel statistics and videos, helping users manage their content and understand their audience.
- Likes Controller: Facilitates toggling of like status on videos, comments, and tweets, and retrieving liked videos, enhancing user interaction.
- Playlist Controller: Allows users to create, update, and delete playlists, and manage videos within playlists, offering a personalized viewing experience.
- Subscription Controller: Manages channel subscriptions, enabling users to subscribe to channels and retrieve their subscribed channels and subscribers.
- Tweet Controller: Provides endpoints for creating, updating, and deleting tweets, supporting additional user interaction.
- Video Controller: Handles video publishing, retrieval, updating, and deletion, including managing video files and thumbnails.
Each controller is designed to ensure data integrity, security, and efficient user interaction. This modular approach makes the backend robust, scalable, and maintainable, capable of supporting a YouTube-like platform effectively.
Contributions are welcome! If you find any bugs or want to suggest enhancements, please open an issue or submit a pull request.
This project is licensed under nothing, lol feel free to use it for educational purposes