TweetTube is a full-stack video sharing application with:
- an
Express+MongoDBbackend API - a
React+Vitefrontend - JWT-based authentication
- Cloudinary media uploads
- features for videos, comments, likes, subscriptions, tweets, playlists, dashboard stats, and watch history
This README is focused on setup and deployment.
- Node.js
- Express
- MongoDB Atlas with Mongoose
- JWT auth
- Multer
- Cloudinary
- React
- React Router
- Axios
- Vite
.
├── src/ # Backend source
├── public/ # Backend public assets
├── frontend/ # React + Vite frontend
├── package.json # Backend package.json
└── readme.md
Make sure these are installed before running or deploying:
- Node.js 18+ recommended
- npm 9+ recommended
- MongoDB Atlas database
- Cloudinary account
Create a .env file in the project root for the backend.
Example:
PORT=8000
MONGODB_URI=your_mongodb_connection_string
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
CORS_ORIGIN=http://localhost:5173Notes:
- the backend database name is appended in code as
BACKENDDB - never commit real secrets to Git
- example files are available at .env.example and frontend/.env.example
- if you deploy the frontend and backend on different domains, set
CORS_ORIGINorFRONTEND_URLfor the deployed frontend
npm installcd frontend
npm installFrom the project root:
npm run devBackend runs on:
http://localhost:8000
From frontend/:
npm run devFrontend runs on:
http://localhost:5173
The backend health endpoint is:
GET /api/v1/healthcheck
Example:
http://localhost:8000/api/v1/healthcheck
Create a frontend env file when needed, for example frontend/.env.production:
VITE_API_BASE_URL=https://your-backend-domain.com/api/v1
VITE_BASE_PATH=/backend_project/Notes:
- use
VITE_API_BASE_URLto point the frontend at your deployed backend - use
VITE_BASE_PATHwhen deploying under a subpath such as GitHub Pages project sites - for local development,
VITE_BASE_PATH=/is correct
The frontend now reads its API URL from frontend/src/api/api.js using VITE_API_BASE_URL.
Example:
VITE_API_BASE_URL=https://your-backend-domain.com/api/v1You can deploy the backend to platforms like:
- Render
- Railway
- Cyclic
- VPS with PM2 and Nginx
- Push the project to GitHub.
- Create a backend service on your hosting platform.
- Set the root directory to the repository root.
- Add all backend environment variables from the
.envexample. - Use this install command:
npm install- Use this start command:
node src/index.js- add all environment variables
- verify MongoDB Atlas network access allows your host
- verify Cloudinary credentials are correct
- confirm the deployed backend can respond at
/api/v1/healthcheck - update CORS in src/app.js to allow your frontend domain
You can deploy the frontend to platforms like:
- Vercel
- Netlify
- Cloudflare Pages
- Render Static Site
From frontend/:
npm install
npm run buildThe production build output is generated in:
frontend/dist
- Set your frontend environment variables.
For GitHub Pages project deployment:
VITE_API_BASE_URL=https://your-backend-domain.com/api/v1
VITE_BASE_PATH=/backend_project/For root-domain static deployment:
VITE_API_BASE_URL=https://your-backend-domain.com/api/v1
VITE_BASE_PATH=/- Build the frontend:
cd frontend
npm run build- Deploy the
frontend/distfolder to your static host. - If using GitHub Pages, the included
404.htmlprovides SPA route fallback for refreshes.
This repo now includes an automatic GitHub Pages workflow at .github/workflows/deploy-pages.yml.
For this repository, it builds with:
VITE_BASE_PATH=/backend_project/Before the deployed app can call your backend, set this GitHub repository variable:
VITE_API_BASE_URL
Example value:
https://your-backend-domain.com/api/v1
Then in GitHub:
- Open the repository.
- Go to
Settings. - Go to
Pages. - Set
SourcetoGitHub Actions. - Go to
Settings > Secrets and variables > Actions > Variables. - Add
VITE_API_BASE_URLwith your deployed backend URL. - Push to
mainto trigger deployment.
Recommended setup:
- deploy the backend separately as an API service
- deploy the frontend separately as a static site
- point the frontend API base URL to the deployed backend
Example:
- frontend:
https://tweettube.vercel.app - backend:
https://tweettube-api.onrender.com
Then set:
VITE_API_BASE_URL=https://tweettube-api.onrender.com/api/v1
VITE_BASE_PATH=/And allow the frontend origin in backend CORS with CORS_ORIGIN=https://tweettube.vercel.app.
Likely causes:
- frontend still points to
localhost VITE_BASE_PATHdoes not match the deployed subpath- backend CORS does not allow the frontend domain
- backend server is down
Likely causes:
- secure cookie settings in production
- frontend and backend are on different domains
- CORS and credentials are not configured correctly
Likely causes:
- Cloudinary keys are missing or invalid
- upload file size is too large
- temporary file handling fails on the deployment platform
Likely causes:
- invalid MongoDB URI
- MongoDB Atlas IP/network rules are blocking the host
npm run dev
node src/index.jscd frontend
npm run dev
npm run buildFor a cleaner production deployment, consider:
- adding a backend
startscript in rootpackage.json - hiding debug
console.logoutput in backend upload/auth code - adding deployment configs for Render, Railway, or Vercel
Built as a full-stack backend-focused learning project and expanded into the TweetTube UI.
Special credit to Hitesh Choudhary, whose teaching and backend content helped shape the learning journey behind this project.