A production-style Node.js + Express backend for a video-sharing platform (YouTube-like), with JWT auth, media upload, subscriptions, playlists, comments, tweets, likes, and channel dashboards.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Mongoose)
- Auth: JWT access + refresh token flow
- Media storage: Cloudinary
- Uploads: Multer
- Utilities: cookie-parser, cors, bcrypt
- User registration/login/logout with secure token handling
- Access token refresh workflow
- Profile update, avatar upload, cover image upload
- Video upload/update/delete + publish toggle + view count
- Comments on videos
- Likes for videos/comments/tweets
- Channel subscription/unsubscription
- Playlist create/update/delete and add/remove videos
- Tweet-style short updates per user
- Dashboard endpoints for channel analytics and videos
- Healthcheck endpoint for uptime monitoring
src/
app.js
index.js
constants.js
controllers/
models/
routes/
middlewares/
utils/
db/
git clone https://github.com/dipexplorer/VideTube.git
cd VideTube
npm installcp .env.example .envUpdate .env with your real values (especially MongoDB URI, JWT secrets, and Cloudinary credentials).
Multer writes temporary files into public/temp before Cloudinary upload.
mkdir -p public/tempnpm run devor
npm startDefault local URL: http://localhost:3000
Use .env.example as the source of truth.
| Variable | Required | Example | Description |
|---|---|---|---|
PORT |
No | 3000 |
API server port |
NODE_ENV |
No | development |
Runtime environment |
CORS_ORIGIN |
No | http://localhost:5173 |
Allowed frontend origin |
DB_URL |
Yes | mongodb://127.0.0.1:27017 |
MongoDB base URI (DB name appended internally) |
JWT_ACCESS_TOKEN_SECRET |
Yes | long-random-secret |
JWT access signing secret |
JWT_ACCESS_TOKEN_EXPIRY |
Yes | 1d |
Access token TTL |
JWT_REFRESH_TOKEN_SECRET |
Yes | long-random-secret |
JWT refresh signing secret |
JWT_REFRESH_TOKEN_EXPIRY |
Yes | 7d |
Refresh token TTL |
CLOUDINARY_CLOUD_NAME |
Yes (for uploads) | mycloud |
Cloudinary cloud name |
CLOUDINARY_API_KEY |
Yes (for uploads) | 123456789 |
Cloudinary key |
CLOUDINARY_API_SECRET |
Yes (for uploads) | ******** |
Cloudinary secret |
All endpoints are mounted under:
/api/v1
GET /healthcheckPOST /user/registerPOST /user/loginPOST /user/logoutPOST /user/refresh-tokenGET /user/accountGET /video/searchPOST /video/uploadGET /video/:idPOST /video/:videoId/commentPOST /subscription/:channelIdPOST /playlistPOST /like/video/:videoIdPOST /tweetGET /dashboard/:channelId/stats
Full route behavior depends on JWT-protected middleware and controller-level checks.
- Use Postman/Insomnia to test multipart routes (
avatar,coverImage,thumbnail,videoFile). - Keep secrets out of git (
.envis already ignored). - Generate strong JWT secrets (
openssl rand -hex 32). - If CORS errors appear, verify
CORS_ORIGINand frontend URL/port match.
- MongoDB connection fails: verify
DB_URLand DB server availability. - Upload fails: verify Cloudinary values and ensure
public/tempexists. - Unauthorized (401): check token cookie/header and refresh token flow.
npm run dev # Run with nodemon
npm start # Run with node
npm test # Placeholder test scriptISC