A robust backend service for a video-sharing platform inspired by YouTube. This project provides a comprehensive API for managing users, videos, comments, playlists, subscriptions, and more.
-
User Management
- Registration and authentication
- Profile management
- Secure password handling
- JWT-based authentication
-
Video Management
- Upload and stream videos
- Video metadata (title, description)
- View tracking
- Toggle publish status
-
Social Features
- Comments on videos
- Like/unlike videos, comments, and tweets
- Subscribe to channels
- Create and share tweets
-
Content Organization
- Create and manage playlists
- Add/remove videos from playlists
- User watch history
-
Channel Dashboard
- View channel statistics
- Manage uploaded content
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- File Storage: Cloudinary
- File Handling: Multer
- Security: bcryptjs for password hashing
- Other Tools:
- mongoose-paginate-v2 for pagination
- dotenv for environment variables
src/
├── controllers/ # Business logic handlers
├── models/ # Mongoose schemas
├── routes/ # API routes
├── middlewares/ # Custom middlewares
├── utils/ # Helper functions
├── db/ # Database connection
├── .env # Environment variables
└── index.js # Application entry point
- Node.js (v14 or higher)
- MongoDB
- Cloudinary account
-
Clone the repository
git clone <repository-url> cd Backend
-
Install dependencies
npm install
-
Create a
.envfile in thesrcdirectory based on.env.samplePORT=8000 CORS_ORIGIN=* MONGO_URI=<your-mongodb-connection-string> ACCESS_TOKEN_SECRET=<your-jwt-secret> ACCESS_TOKEN_EXPIRY=1d REFRESH_TOKEN_SECRET=<your-refresh-token-secret> REFRESH_TOKEN_EXPIRY=7d CLOUDINARY_CLOUD_NAME=<your-cloudinary-cloud-name> CLOUDINARY_API_KEY=<your-cloudinary-api-key> CLOUDINARY_API_SECRET=<your-cloudinary-api-secret> -
Start the development server
npm run dev
-
The API will be available at
http://localhost:8000
POST /api/v1/users/register- Register a new userPOST /api/v1/users/login- Login a userPOST /api/v1/users/logout- Logout a userPOST /api/v1/users/refresh-token- Refresh access token
GET /api/v1/users/get-current-user- Get current user detailsPOST /api/v1/users/change-password- Change user passwordPUT /api/v1/users/update-account- Update account detailsPATCH /api/v1/users/update-avatar- Update user avatarPATCH /api/v1/users/update-cover-image- Update user cover imageGET /api/v1/users/channel/:username- Get channel profileGET /api/v1/users/watch-history- Get user watch history
GET /api/v1/videos- Get all videosPOST /api/v1/videos- Upload a new videoGET /api/v1/videos/:videoId- Get a specific videoPATCH /api/v1/videos/:videoId- Update a videoDELETE /api/v1/videos/:videoId- Delete a videoPATCH /api/v1/videos/toggle/publish/:videoId- Toggle publish status
GET /api/v1/comments/:videoId- Get all comments for a videoPOST /api/v1/comments/:videoId- Add a comment to a videoPATCH /api/v1/comments/c/:commentId- Update a commentDELETE /api/v1/comments/c/:commentId- Delete a comment
POST /api/v1/likes/toggle/v/:videoId- Toggle like on a videoPOST /api/v1/likes/toggle/c/:commentId- Toggle like on a commentPOST /api/v1/likes/toggle/t/:tweetId- Toggle like on a tweetGET /api/v1/likes/videos- Get all liked videos
POST /api/v1/playlists- Create a new playlistGET /api/v1/playlists/:playlistId- Get a specific playlistPATCH /api/v1/playlists/:playlistId- Update a playlistDELETE /api/v1/playlists/:playlistId- Delete a playlistPATCH /api/v1/playlists/add/:videoId/:playlistId- Add video to playlistPATCH /api/v1/playlists/remove/:videoId/:playlistId- Remove video from playlistGET /api/v1/playlists/user/:userId- Get all playlists for a user
POST /api/v1/subscriptions/c/:channelId- Toggle subscription to a channelGET /api/v1/subscriptions/c/:channelId- Get subscribed channelsGET /api/v1/subscriptions/u/:subscriberId- Get channel subscribers
POST /api/v1/tweets- Create a new tweetGET /api/v1/tweets/user/:userId- Get user tweetsPATCH /api/v1/tweets/:tweetId- Update a tweetDELETE /api/v1/tweets/:tweetId- Delete a tweet
GET /api/v1/dashboard/stats- Get channel statisticsGET /api/v1/dashboard/videos- Get channel videos
- Password hashing with bcryptjs
- JWT-based authentication
- HTTP-only cookies for token storage
- Input validation
- Error handling middleware
ApiError- Custom error handlingApiResponse- Standardized API responsesasyncHandler- Async function wrapper for error handlingcloudinary- File upload and management
Run the server in development mode:
npm run devStart the server in production mode:
npm startThis project is licensed under the ISC License.
Haseeb Sajjad (haseeb-012)