Skip to content

Wcoder547/js_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 

Repository files navigation

js_backend 🎬

A YouTube-style video platform backend — REST API built with Node.js, Express, and MongoDB, covering users, videos, likes, comments, playlists, subscriptions, tweets, and a stats dashboard.

Built as a hands-on learning project from the Chai aur Code course. There's no frontend — the entire focus is on building a clean, modular, production-style backend that you can explore and test with Postman.


Table of Contents


Features

  • Users — register, login, update profile; passwords hashed with bcrypt, sessions managed with JWT
  • Videos — upload, fetch, update, delete; files handled by Multer and stored on Cloudinary
  • Likes — toggle like/unlike on videos, tracked per user
  • Comments — add and fetch comments on any video, linked to author and video
  • Playlists — create playlists, add or remove videos, manage personal collections
  • Subscriptions — subscribe/unsubscribe to channels; fetch subscribers and subscriptions
  • Tweets — post and fetch short micro-posts as a lightweight social feed on top of video content
  • Dashboard — aggregated stats endpoint (total videos, users, likes) for admin or user analytics

Tech Stack

Layer Technology
Runtime Node.js
Framework Express.js
Database MongoDB (Mongoose)
Auth JWT + bcrypt
File Uploads Multer → Cloudinary
Pagination mongoose-aggregate-paginate-v2
Dev nodemon, Prettier, dotenv

Getting Started

Prerequisites

  • Node.js v18+
  • MongoDB (local or Atlas)
  • A Cloudinary account

Installation

# 1. Clone the repo
git clone https://github.com/Wcoder547/js_backend.git
cd js_backend

# 2. Install dependencies
npm install

# 3. Add environment variables (see below)
cp .env.example .env

# 4. Start the dev server
npm run dev

Server starts at http://localhost:5000 and watches for file changes via nodemon.


Environment Variables

Create a .env file in the project root:

PORT=5000
MONGODB_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/mydb
JWT_SECRET=your_jwt_secret_key

CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

API Reference

Test all endpoints with Postman or any HTTP client. Protected routes require a Bearer <token> header.

Auth

Method Endpoint Auth Description
POST /api/users/register Register a new user
POST /api/users/login Login and receive JWT

Videos

Method Endpoint Auth Description
GET /api/videos List all videos (paginated)
GET /api/videos/:id Get a single video by ID
POST /api/videos Upload a video (multipart/form-data)
PATCH /api/videos/:id Update video details
DELETE /api/videos/:id Delete a video

Interactions

Method Endpoint Auth Description
POST /api/videos/:id/like Toggle like on a video
POST /api/videos/:id/comments Add a comment
POST /api/playlists Create a playlist
POST /api/subscriptions Subscribe to a channel
POST /api/tweets Post a tweet
GET /api/dashboard Get aggregated stats

Example — Upload a Video

POST /api/videos
Authorization: Bearer <token>
Content-Type: multipart/form-data

Fields:
  file        → video file
  title       → "My First Video"
  description → "A short description"

Example — Add a Comment

POST /api/videos/:id/comments
Authorization: Bearer <token>

{
  "text": "Great video!"
}

Project Structure

js_backend/
├── src/
│   ├── controllers/      # Request handlers (user, video, comment, etc.)
│   ├── models/           # Mongoose schemas (User, Video, Comment, etc.)
│   ├── routes/           # Express route definitions
│   ├── middleware/        # JWT auth, error handling
│   ├── config/           # DB connection, Cloudinary setup
│   └── server.js         # App entry point
├── datamodeling/         # Data model diagrams and planning
├── .env.example
└── README.md

Contributing

Contributions, bug reports, and feature requests are welcome.

  1. Fork the repository
  2. Create a branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m "add: your feature"
  4. Push and open a Pull Request

Prettier is configured — run npx prettier --write . before committing.


About

This project was built to go beyond tutorial-level Node.js and understand how a real video platform backend is structured — auth flows, cloud media storage, relational-style queries in MongoDB via aggregation pipelines, and clean separation of concerns across controllers, models, routes, and middleware.

It covers the full surface area of a backend engineer's daily work: protecting routes, handling file uploads, paginating large datasets, and exposing a consistent REST API that a frontend or mobile app could consume.

Built by Waseem Akram — Full-Stack Developer and DevOps Engineer based in Pakistan, working across the MERN stack, Generative AI integrations, and cloud automation.


License

MIT © Waseem Akram

About

This repository focuses on JavaScript backend development using Node.js and Express.js, covering REST APIs, middleware, authentication, file uploads, and modular architecture. Ideal for developers building scalable server-side applications with pure JavaScript.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages