Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VideoTube

A Node.js backend API for a video hosting platform, modeled after YouTube. Supports user authentication, profile management, media uploads via Cloudinary, and core social features such as subscriptions. Built with Express, MongoDB, and JWT-based security.

Features

  • User registration and login with email or username
  • Secure password hashing (bcrypt)
  • Access and refresh token authentication (JWT)
  • Protected routes with middleware
  • Avatar and cover image upload (Multer + Cloudinary)
  • Account details update and password change
  • Token refresh and logout
  • Subscription model (subscriber/channel relationship)
  • Video model with aggregation pagination support
  • Standardized API responses and error handling

Tech Stack

  • Runtime: Node.js (ES Modules)
  • Framework: Express 5
  • Database: MongoDB with Mongoose
  • Authentication: JWT + bcrypt
  • File Upload: Multer + Cloudinary
  • Other: cookie-parser, cors, dotenv, mongoose-aggregate-paginate-v2

Prerequisites

  • Node.js >= 18
  • MongoDB instance (local or Atlas)
  • Cloudinary account

Installation

git clone https://github.com/SupriyoP09/VideoTube.git
cd VideoTube
npm install

Environment Variables

Create a .env file in the root directory:

PORT=8000
MONGODB_URI=
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_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

Running the Server

npm run dev

The server starts on the port defined in .env (default 8000).

API Endpoints

Base path: /api/v1/user

Method Endpoint Auth Required Description
POST /register No Register a new user
POST /login No Login and receive tokens
POST /logout Yes Logout and clear cookies
POST /refresh-token No Refresh access token

Additional controller methods exist for password change, current user retrieval, and profile/image updates. These can be wired to routes as needed.

Project Structure

src/
├── app.js                 # Express app setup and middleware
├── index.js               # Entry point and DB connection
├── constants.js           # Application constants
├── controllers/           # Route handlers
├── db/                    # Database connection
├── middlewares/           # Auth and Multer middleware
├── models/                # Mongoose schemas (User, Video, Subscription)
├── routes/                # API route definitions
└── utils/                 # ApiError, ApiResponse, asyncHandler, Cloudinary helper
public/
└── temp/                  # Temporary upload directory

Notes

  • Avatar is required on registration; cover image is optional.
  • Refresh tokens are stored in the database and validated on refresh.
  • Temporary files are cleaned after successful or failed Cloudinary uploads.
  • The Video and Subscription models are defined and ready for expansion.

About

Backend API for a video hosting platform

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages