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.
- Features
- Tech Stack
- Getting Started
- Environment Variables
- API Reference
- Project Structure
- Contributing
- About
- 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
| 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 |
- Node.js v18+
- MongoDB (local or Atlas)
- A Cloudinary account
# 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 devServer starts at http://localhost:5000 and watches for file changes via nodemon.
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_secretTest all endpoints with Postman or any HTTP client. Protected routes require a Bearer <token> header.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/users/register |
❌ | Register a new user |
| POST | /api/users/login |
❌ | Login and receive JWT |
| 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 |
| 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 |
POST /api/videos
Authorization: Bearer <token>
Content-Type: multipart/form-data
Fields:
file → video file
title → "My First Video"
description → "A short description"
POST /api/videos/:id/comments
Authorization: Bearer <token>
{
"text": "Great video!"
}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
Contributions, bug reports, and feature requests are welcome.
- Fork the repository
- Create a branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m "add: your feature" - Push and open a Pull Request
Prettier is configured — run npx prettier --write . before committing.
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.
MIT © Waseem Akram