This repository contains the backend code for a YouTube-like application, built using Node.js, Express.js, and MongoDB. The application provides a RESTful API for managing users, videos, comments, and other related data.
- User authentication and authorization with JWT
- CRUD operations for users, videos, and comments
- Video upload
- Likes and dislikes for videos
- User subscriptions
- Robust error handling and validation
- Node.js: JavaScript runtime
- Express.js: Web framework for Node.js
- MongoDB: NoSQL database
- Mongoose: ODM for MongoDB
- JWT: JSON Web Tokens for authentication
- Multer: Middleware for handling multipart/form-data requests
- Cloudinary: Cloud storage for video uploads
- Node.js (v14 or later)
- MongoDB
-
Clone the repository:
git clone https://github.com/gagankumar007/youtube-backend.git cd youtube-backend
-
Install dependencies:
npm install
-
Set up environment variables (see Configuration).
-
Start the MongoDB server if not using Docker:
mongod
-
Start the development server:
npm run dev
Create a .env
file in the root directory with the following environment variables:
PORT=8000
MONGO_URI=mongodb://localhost:27017/youtube_backend
JWT_SECRET=your_jwt_secret
npm start
The server will start on http://localhost:8000
.
POST /api/auth/register
: Register a new userPOST /api/auth/login
: Login a user
GET /api/users/:id
: Get user by IDPUT /api/users/:id
: Update user by IDDELETE /api/users/:id
: Delete user by ID
POST /api/videos
: Upload a new videoGET /api/videos/:id
: Get video by IDPUT /api/videos/:id
: Update video by IDDELETE /api/videos/:id
: Delete video by ID
POST /api/videos/:videoId/comments
: Add a comment to a videoGET /api/videos/:videoId/comments
: Get all comments for a videoDELETE /api/comments/:id
: Delete a comment by ID
POST /api/videos/:videoId/like
: Like a videoPOST /api/videos/:videoId/dislike
: Dislike a video
POST /api/users/:id/subscribe
: Subscribe to a userPOST /api/users/:id/unsubscribe
: Unsubscribe from a user
Contributions are welcome! Please fork the repository and create a pull request with your changes.