A robust backend API for a video streaming platform similar to YouTube, built with Node.js, Express, and MongoDB.
- User Management: Registration, authentication, profile management with avatar and cover images
- Video Management: Upload, publish, update, delete videos with thumbnail support
- Subscription System: Subscribe/unsubscribe to channels
- Playlist Management: Create, update, delete playlists and manage videos within them
- Comments: Add, update, delete comments on videos
- Likes: Like/unlike videos, comments, and tweets
- Tweets: Create, update, delete tweets (community posts)
- Dashboard: Channel statistics and video analytics
- Watch History: Track user's video watch history
- Runtime: Node.js
- Framework: Express.js v5
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- File Upload: Multer
- Cloud Storage: Cloudinary (for images and videos)
- Password Hashing: bcrypt
Before running this project, make sure you have:
- Node.js (v18 or higher recommended)
- MongoDB instance (local or cloud like MongoDB Atlas)
- Cloudinary account for media storage
-
Clone the repository
git clone <repository-url>
cd backend
-
Install dependencies
-
Set up environment variables
Create a .env file in the root directory with the following variables:
PORT=8000
MONGODB_URI=your_mongodb_connection_string
CORS_ORIGIN=http://localhost:5173
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_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
-
Run the development server
The server will start at http://localhost:8000
| Method |
Endpoint |
Description |
| GET |
/api/v1/healthcheck |
Check API health status |
| Method |
Endpoint |
Description |
Auth |
| POST |
/api/v1/users/register |
Register a new user |
No |
| POST |
/api/v1/users/login |
Login user |
No |
| POST |
/api/v1/users/logout |
Logout user |
Yes |
| POST |
/api/v1/users/refreshUser |
Refresh access token |
Yes |
| POST |
/api/v1/users/changePassword |
Change password |
Yes |
| POST |
/api/v1/users/getCurrentUser |
Get current user details |
Yes |
| PATCH |
/api/v1/users/updateUserDetails |
Update user details |
Yes |
| PATCH |
/api/v1/users/updateAvatar |
Update user avatar |
Yes |
| PATCH |
/api/v1/users/updateUserCoverImage |
Update cover image |
Yes |
| GET |
/api/v1/users/channel/:username |
Get channel profile |
Yes |
| GET |
/api/v1/users/getWatchHistory |
Get watch history |
Yes |
| Method |
Endpoint |
Description |
Auth |
| GET |
/api/v1/videos/getAllVideos |
Get all videos |
Yes |
| POST |
/api/v1/videos/publishAVideo |
Upload and publish a video |
Yes |
| GET |
/api/v1/videos/video/:videoId |
Get video by ID |
Yes |
| PATCH |
/api/v1/videos/video/:videoId |
Update video |
Yes |
| DELETE |
/api/v1/videos/video/:videoId |
Delete video |
Yes |
| PATCH |
/api/v1/videos/toggle/publish/:videoId |
Toggle publish status |
Yes |
| Method |
Endpoint |
Description |
Auth |
| GET |
/api/v1/subscriptions/c/:channelId |
Get subscribed channels |
Yes |
| POST |
/api/v1/subscriptions/c/:channelId |
Toggle subscription |
Yes |
| GET |
/api/v1/subscriptions/u/:subscriberId |
Get channel subscribers |
Yes |
| Method |
Endpoint |
Description |
Auth |
| POST |
/api/v1/playlists/ |
Create a playlist |
Yes |
| GET |
/api/v1/playlists/:playlistId |
Get playlist by ID |
Yes |
| PATCH |
/api/v1/playlists/:playlistId |
Update playlist |
Yes |
| DELETE |
/api/v1/playlists/:playlistId |
Delete playlist |
Yes |
| PATCH |
/api/v1/playlists/add/:videoId/:playlistId |
Add video to playlist |
Yes |
| PATCH |
/api/v1/playlists/remove/:videoId/:playlistId |
Remove video from playlist |
Yes |
| GET |
/api/v1/playlists/user/:userId |
Get user's playlists |
Yes |
Comments
| Method |
Endpoint |
Description |
Auth |
| GET |
/api/v1/comments/:videoId |
Get video comments |
Yes |
| POST |
/api/v1/comments/:videoId |
Add comment |
Yes |
| PATCH |
/api/v1/comments/c/:commentId |
Update comment |
Yes |
| DELETE |
/api/v1/comments/c/:commentId |
Delete comment |
Yes |
| Method |
Endpoint |
Description |
Auth |
| POST |
/api/v1/likes/toggle/v/:videoId |
Toggle video like |
Yes |
| POST |
/api/v1/likes/toggle/c/:commentId |
Toggle comment like |
Yes |
| POST |
/api/v1/likes/toggle/t/:tweetId |
Toggle tweet like |
Yes |
| GET |
/api/v1/likes/videos |
Get liked videos |
Yes |
Tweets
| Method |
Endpoint |
Description |
Auth |
| POST |
/api/v1/tweets/ |
Create a tweet |
Yes |
| GET |
/api/v1/tweets/user/:userId |
Get user tweets |
Yes |
| PATCH |
/api/v1/tweets/:tweetId |
Update tweet |
Yes |
| DELETE |
/api/v1/tweets/:tweetId |
Delete tweet |
Yes |
| Method |
Endpoint |
Description |
Auth |
| GET |
/api/v1/dashboard/stats |
Get channel stats |
Yes |
| GET |
/api/v1/dashboard/videos |
Get channel videos |
Yes |
src/
βββ app.js # Express app configuration
βββ index.js # Entry point
βββ constant.js # Application constants
βββ controllers/ # Request handlers
βββ db/ # Database connection
βββ middlewares/ # Custom middlewares (auth, file upload)
βββ models/ # Mongoose schemas
βββ routes/ # API routes
βββ utils/ # Utility functions (ApiError, ApiResponse, etc.)
| Command |
Description |
npm run dev |
Start development server with nodemon |
npm test |
Run tests |
- username, email, fullName, avatar, coverImage
- password (hashed), refreshToken
- watchHistory (references to videos)
- videoFile, thumbnail, title, description
- duration, views, isPublished
- owner (reference to user)
- name, description, videos, owner
Comment
- video/comment/tweet, likedBy
Tweet
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request