A scalable and feature-rich backend for a YouTube-like application, built with Node.js, Express, and MongoDB. This API provides endpoints for user authentication, video management, comments, and more, ensuring a seamless experience for video-sharing platforms.
- User Authentication: JWT-based login and signup.
- Video Management: Upload, delete, and manage videos.
- Comments System: Add, edit, and delete comments on videos.
- Like & Dislike: Interaction features for videos.
- Playlists: Create and manage user-specific playlists.
- Backend: Node.js, Express.js
- Database: MongoDB, Mongoose
- Storage: Cloud-based video storage using AWS S3 (or similar).
- Authentication: JSON Web Tokens (JWT)
youtube-backend/
│
├── src/
│ ├── controllers/ # Route handlers
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ ├── middlewares/ # Custom middleware
│ ├── utils/ # Helper functions
│ ├── app.js # Express app setup
│ ├── constants.js # Constants used throughout the Project
| └── index.js # Start point of the app
│
├── .env.example # Environment variables
├── package.json # Project dependencies
├── .gitignore # Template of files to unstage for git
├── .prettierrc # Prettier Configuration Files
├── .prettierignore # Template of files for prettier to ignore
└── README.md # Project documentation
- Node.js: v16+
- MongoDB: Running locally or a cloud instance (e.g., MongoDB Atlas).
- Cloudinary: For video and images uploads (or similar storage service).
-
Clone the repository:
git clone https://github.com/rounakkumarsingh/youtube-backend.git cd youtube-backend
-
Install dependencies:
npm install
-
Create a
.env
file based on.env.example
and add your configuration:PORT= MONGODB_URI= CORS_ORIGIN= ACCESS_TOKEN_SECRET= ACCESS_TOKEN_EXPIRY= REFRESH_TOKEN_SECRET= REFRESH_TOKEN_EXPIRY= CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET=
-
Start the development server:
npm run dev
-
Access the API at
http://localhost:5000
.
POST /api/auth/signup
- Register a new user.POST /api/auth/login
- User login.
POST /api/videos/upload
- Upload a new video.DELETE /api/videos/:id
- Delete a video.GET /api/videos/:id
- Get video details.
POST /api/videos/:id/comments
- Add a comment to a video.DELETE /api/comments/:id
- Delete a comment.
POST /api/playlists
- Create a new playlist.GET /api/playlists/:userId
- Get playlists of a user.
Run tests using:
npm test
-
Deploy to Heroku:
- Connect your repository to a new Heroku app.
- Set up environment variables in the Heroku dashboard.
-
AWS EC2:
- Set up an EC2 instance.
- Install Node.js, MongoDB, and PM2.
- Clone the repository and start the server using PM2.
Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.