A complete backend API for a Netflix clone built with Node.js, Express, and MongoDB.
- π₯ Trending Section API - Fetch trending movies/shows
- π¬ Movie Management - CRUD operations for movies
- π Authentication - User signup, login with JWT
- β€οΈ Watchlist - Add/remove movies to user's watchlist
- π Search - Search movies with filters
- π‘οΈ Route Protection - Middleware for protected routes
- User ratings and reviews
- Recommendation system
- Video streaming endpoints
- Social features
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- Validation: Express-validator
- Security: bcryptjs for password hashing
- CORS: Enabled for frontend integration
- Node.js (v14 or higher)
- MongoDB (local or cloud)
- npm or yarn
git clone <your-repo-url>
cd netflix-clone
npm installCopy the config file and update with your values:
cp config.env.example config.envUpdate config.env:
MONGODB_URI=mongodb://localhost:27017/netflix-clone
JWT_SECRET=your-super-secret-jwt-key-change-this
PORT=5000
NODE_ENV=developmentLocal MongoDB:
# Start MongoDB service
mongod
# Or using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latestCloud MongoDB (MongoDB Atlas):
- Create account at MongoDB Atlas
- Create cluster and get connection string
- Update
MONGODB_URIin config.env
npm run seed# Development mode
npm run dev
# Production mode
npm startServer will start at: http://localhost:5000
GET /api/movies/trending
Returns trending movies with isTrending: true
GET /api/movies # Get all movies with pagination
GET /api/movies/:id # Get movie by ID
POST /api/movies # Add new movie (admin only)
PUT /api/movies/:id # Update movie (admin only)
DELETE /api/movies/:id # Delete movie (admin only)
GET /api/movies/search?q=dark&genre=horror&year=2020&rating=8
POST /api/auth/signup # User registration
POST /api/auth/login # User login
GET /api/auth/profile # Get user profile (protected)
PUT /api/auth/profile # Update profile (protected)
GET /api/watchlist # Get user's watchlist (protected)
POST /api/watchlist # Add movie to watchlist (protected)
DELETE /api/watchlist/:movieId # Remove from watchlist (protected)
PUT /api/watchlist/:movieId # Update watchlist item (protected)
GET /api/watchlist/status/:movieId # Check watchlist status (protected)
curl http://localhost:5000/api/movies/trendingcurl "http://localhost:5000/api/movies/search?q=stranger"curl -X POST http://localhost:5000/api/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123",
"username": "testuser"
}'# First get token from login
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'
# Use token in Authorization header
curl http://localhost:5000/api/watchlist \
-H "Authorization: Bearer YOUR_TOKEN_HERE"netflix-clone/
βββ models/ # Database models
β βββ Movie.js # Movie schema
β βββ User.js # User schema
β βββ Watchlist.js # Watchlist schema
βββ controllers/ # Route controllers
β βββ movieController.js
β βββ authController.js
β βββ watchlistController.js
βββ routes/ # API routes
β βββ movies.js
β βββ auth.js
β βββ watchlist.js
βββ middleware/ # Custom middleware
β βββ auth.js # JWT authentication
β βββ validation.js # Input validation
βββ scripts/ # Utility scripts
β βββ seedMovies.js # Database seeder
βββ server.js # Main server file
βββ package.json # Dependencies
βββ config.env # Environment variables
βββ README.md # This file
MONGODB_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT tokensPORT: Server port (default: 5000)NODE_ENV: Environment (development/production)
- Movies: title, description, genre, rating, poster/banner URLs, trending flags
- Users: email, password (hashed), username, admin status, watchlist
- Watchlist: user reference, movie reference, watched status, rating, notes
This project is configured for easy deployment to cloud platforms.
- Backend: Deploy to Render using
render.yamlconfiguration - Frontend: Deploy to Netlify/Vercel using provided config files
- Full Guide: See
deployment.mdfor complete step-by-step instructions
render.yaml- Render deployment configurationnetlify.toml- Netlify deployment settingsvercel.json- Vercel deployment configuration.env.example- Environment variables templatejs/config.js- Frontend environment configurationdeployment.md- Complete deployment guide
NODE_ENV=production npm start- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
This project is licensed under the ISC License.
Made with β€οΈ by Rohit
Happy Coding! π¬β¨