Skip to content

Working on building REST API for MyTube a clone of YouTube

Notifications You must be signed in to change notification settings

SayanBanerjee-007/My_Tube_Backend

Repository files navigation

My Tube Backend

License Node.js Express.js MongoDB

Table of Contents

Project Overview

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.

Features

  • 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

Prerequisites

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)

Installation

Follow these steps to set up and run the application locally:

  1. Clone the Repository

    git clone https://github.com/SayanBanerjee-007/My_Tube_Backend.git
    cd My_Tube_Backend
  2. Install Dependencies

    npm install
  3. 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.:

Running the Application

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.

Development Mode

For development mode with live-reloading, use:

npm run dev

This command uses nodemon to automatically restart the server upon code changes.

Accessing the Application

Once the server is running, you can access the API endpoints via:

http://localhost:5000/api

API Documentation

Authentication

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"
}

Users

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

Videos

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

Comments

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.

Releases

No releases published

Packages

No packages published