This is the backend for a video-sharing platform built using Node.js, Express, and MongoDB. It provides APIs for user authentication, video management, subscriptions, playlists, likes, comments, and more.
- User Authentication: Register, login, logout, and token-based authentication.
- Video Management: Upload, update, delete, and fetch videos.
- Subscriptions: Subscribe to channels and manage subscriptions.
- Playlists: Create, update, and manage playlists.
- Likes: Like videos, comments, and tweets.
- Comments: Add, update, and delete comments on videos.
- Tweets: Post, update, and delete tweets.
- Dashboard: Fetch channel statistics and videos.
- Healthcheck: API to check server health.
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose
- File Uploads: Cloudinary
- Authentication: JWT (JSON Web Tokens)
- Middleware: Multer for file uploads, Cookie-Parser for cookies
- Utilities: Async error handling, custom error and response classes
-
Clone the repository:
git clone <repository-url> cd VideoSharingPlatform_BACKEND
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory and configure the following variables:PORT=8000 MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/ CORS_ORIGIN=* 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>
-
Start the development server:
npm run dev
-
The server will run at
http://localhost:8000.
POST /api/v1/users/register: Register a new user.POST /api/v1/users/login: Login a user.POST /api/v1/users/logout: Logout a user.GET /api/v1/users/current-user: Get the current logged-in user.
GET /api/v1/videos: Fetch all videos.POST /api/v1/videos: Upload a new video.PATCH /api/v1/videos/:videoId: Update video details.DELETE /api/v1/videos/:videoId: Delete a video.
POST /api/v1/subscriptions/c/:channelId: Subscribe to a channel.GET /api/v1/subscriptions/u/:subscriberId: Get subscribed channels.
POST /api/v1/playlist: Create a new playlist.PATCH /api/v1/playlist/:playlistId: Update a playlist.DELETE /api/v1/playlist/:playlistId: Delete a playlist.
POST /api/v1/likes/toggle/v/:videoId: Toggle like on a video.GET /api/v1/likes/videos: Get all liked videos.
GET /api/v1/comments/:videoId: Get comments for a video.POST /api/v1/comments/:videoId: Add a comment to a video.
GET /api/v1/healthcheck: Check server health.
├── src/
│ ├── controllers/ # API controllers
│ ├── db/ # Database connection
│ ├── middlewares/ # Custom middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ ├── utils/ # Utility functions
│ ├── app.js # Express app setup
│ └── index.js # Entry point
├── public/ # Static files
├── .env # Environment variables
├── .gitignore # Git ignore file
├── package.json # Project metadata and dependencies
└── Readme.md # Project documentation
This project is licensed under the ISC License.
Developed by Mayank Sengar.