A full-featured backend REST API for a video sharing platform, built with Node.js, Express, and MongoDB.
It supports user authentication, video uploads, playlists, tweets, likes, subscriptions, and more.
- User Authentication: Register, login, logout, JWT-based auth, password change, refresh tokens.
- Video Management: Upload, update, delete, fetch videos, toggle publish status, watch history.
- Playlists: Create, update, delete playlists, add/remove videos, fetch user playlists.
- Tweets: Post, update, delete tweets, fetch user tweets.
- Likes: Like/unlike videos, comments, tweets, fetch liked videos.
- Subscriptions: Subscribe/unsubscribe to channels, fetch subscribers and subscribed channels.
- Cloudinary Integration: For storing user avatars, cover images, video files, and thumbnails.
- Multer: For handling file uploads.
- Robust Error Handling: Consistent API error and response structure.
- Healthcheck Endpoint: For monitoring API status.
- Node.js (ES Modules)
- Express.js
- MongoDB with Mongoose
- Cloudinary (media storage)
- JWT (authentication)
- Multer (file uploads)
- dotenv (environment variables)
- cookie-parser, cors
git clone <repo-url>
cd Backendnpm installCreate a .env file in the root directory and add the following:
PORT=8000
MONGODB_URI=<your-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-cloudinary-cloud-name>
CLOUDINARY_API_KEY=<your-cloudinary-api-key>
CLOUDINARY_API_SECRET=<your-cloudinary-api-secret>
npm run devThe server will run at http://localhost:8000.
POST /api/v1/users/register— Register a new user (with avatar & cover image)POST /api/v1/users/login— LoginPOST /api/v1/users/logout— LogoutPOST /api/v1/users/refresh-token— Refresh access tokenPOST /api/v1/users/change-password— Change passwordGET /api/v1/users/current-user— Get current user profilePATCH /api/v1/users/update-account— Update user detailsPATCH /api/v1/users/avatar— Update avatarPATCH /api/v1/users/cover-image— Update cover imageGET /api/v1/users/c/:username— Get user channel profileGET /api/v1/users/history— Get watch history
POST /api/v1/videos/— Upload a videoGET /api/v1/videos/— Get all videos (with query, sort, pagination)GET /api/v1/videos/:videoId— Get video by IDPATCH /api/v1/videos/:videoId— Update video detailsDELETE /api/v1/videos/:videoId— Delete videoPATCH /api/v1/videos/:videoId/toggle-publish— Toggle publish status
POST /api/v1/playlists/— Create playlistGET /api/v1/playlists/user/:userId— Get user playlistsPATCH /api/v1/playlists/:playlistId— Update playlistDELETE /api/v1/playlists/:playlistId— Delete playlistPOST /api/v1/playlists/:playlistId/videos/:videoId— Add video to playlist
POST /api/v1/tweets/— Create tweetGET /api/v1/tweets/user/:userId— Get user tweetsPATCH /api/v1/tweets/:tweetId— Update tweetDELETE /api/v1/tweets/:tweetId— Delete tweet
POST /api/v1/likes/video/:videoId— Like/unlike a videoPOST /api/v1/likes/comment/:commentId— Like/unlike a commentPOST /api/v1/likes/tweet/:tweetId— Like/unlike a tweetGET /api/v1/likes/videos— Get liked videos
POST /api/v1/subscriptions/:channelId— Subscribe/unsubscribe to a channelGET /api/v1/subscriptions/channel/:channelId— Get channel subscribersGET /api/v1/subscriptions/user/:subscriberId— Get channels a user is subscribed to
GET /api/v1/healthcheck— Check API status
src/
controllers/
middlewares/
models/
routes/
utils/
app.js
index.js
public/
.env
Based on backend series by https://github.com/hiteshchoudhary
Yash