My Tube Backend is a RESTful API developed with Node.js and Express.js to support a video-sharing platform similar to YouTube. It manages videos, user accounts, and comments. The application connects to a MongoDB database for data persistence.
- User authentication and authorization
- CRUD operations for videos
- CRUD operations for comments
- User profile management
- Token-based authentication with JWT
- Middleware for request validation and error handling
- Structured logging for server activities
- Rate limiting to prevent abuse
Before running this application, ensure you have the following installed on your machine:
- Node.js (version 14.x or higher)
- npm (Node Package Manager, which comes with Node.js)
- MongoDB (local instance or cloud service like MongoDB Atlas)
Follow these steps to set up and run the application locally:
-
Clone the Repository
git clone https://github.com/SayanBanerjee-007/My_Tube_Backend.git cd My_Tube_Backend
-
Install Dependencies
npm install
-
Set Environment Variables
Create a
.env
file in the root directory of the project and copy the content of the.env.sample
file into it. Update the environment variables with your values.:
Once you have configured your environment, you can start the application using:
npm start
The server will start on the specified port (default: 5000) and connect to the MongoDB database.
For development mode with live-reloading, use:
npm run dev
This command uses nodemon to automatically restart the server upon code changes.
Once the server is running, you can access the API endpoints via:
http://localhost:5000/api
Endpoint | Method | Description | Request Body |
---|---|---|---|
/api/auth/register | POST | Register User |
{ "username": "user", "email": "user@example.com", "password": "password" } |
/api/auth/login | POST | Login User |
{ "email": "user@example.com", "password": "password" } |
Endpoint | Method | Description | Request Body |
---|---|---|---|
/api/users | GET | Get All Users | |
/api/users/:id | GET | Get User by ID | |
/api/users/:id | PUT | Update User |
{ "username": "newusername", "email": "newemail@example.com" } |
/api/users/:id | DELETE | Delete User |
Endpoint | Method | Description | Request Body |
---|---|---|---|
/api/videos | GET | Get All Videos | |
/api/videos/:id | GET | Get Video by ID | |
/api/videos | POST | Create Video |
{ "title": "Video Title", "description": "Video Description", "url": "http://video-url.com" } |
/api/videos/:id | PUT | Update Video |
{ "title": "Updated Title", "description": "Updated Description" } |
/api/videos/:id | DELETE | Delete Video |
Endpoint | Method | Description | Request Body |
---|---|---|---|
/api/videos/:videoId/comments | GET | Get All Comments for a Video | |
/api/videos/:videoId/comments | POST | Add Comment to a Video |
{ "text": "Nice video!" } |
/api/comments/:commentId | PUT | Update Comment |
{ "text": "Updated comment text" } |
/api/comments/:commentId | DELETE | Delete Comment |
There are more routes available in the application. You can explore them by running the application and visiting the /api
endpoint.