A Node.js/Express backend API for the Movie App that provides user authentication, movie management, reviews, and watchlist functionality.
- User Authentication: JWT-based authentication with bcrypt password hashing
- Movie Management: Hybrid system combining OMDB API with custom database movies
- Review System: User reviews for both OMDB and custom movies
- Watchlist: Personal movie watchlists for authenticated users
- Admin Features: Admin-only movie creation and management
- Runtime: Node.js (ES Modules)
- Framework: Express.js
- Database: PostgreSQL
- Authentication: JWT + bcrypt
- Validation: express-validator
- Security: Helmet, CORS, Rate limiting
POST /api/auth/login- User loginPOST /api/auth/register- User registrationGET /api/auth/verify- Verify JWT tokenPOST /api/auth/logout- User logoutGET /api/auth/profile- Get user profilePUT /api/auth/profile- Update user profile
GET /api/movies/search?q=query- Search movies (OMDB + Custom)GET /api/movies/:id- Get movie detailsPOST /api/movies- Create custom movie (Admin only)GET /api/movies/lists/featured- Get featured moviesGET /api/movies/lists/top-rated- Get top rated moviesGET /api/movies/lists/new-releases- Get new releasesGET /api/movies/admin/custom-movies- Get all custom movies (Admin)PUT /api/movies/admin/custom-movies/:id- Update custom movie (Admin)DELETE /api/movies/admin/custom-movies/:id- Delete custom movie (Admin)
POST /api/reviews- Create reviewGET /api/reviews/movie/:movieId- Get movie reviewsGET /api/reviews/user/:userId- Get user reviewsGET /api/reviews/my-reviews- Get current user reviewsGET /api/reviews/:id- Get specific reviewPUT /api/reviews/:id- Update review (author only)DELETE /api/reviews/:id- Delete review (author/admin)POST /api/reviews/:id/helpful- Mark review as helpfulGET /api/reviews/lists/recent- Get recent reviews
POST /api/watchlist- Add movie to watchlistGET /api/watchlist- Get user's watchlistDELETE /api/watchlist/:movieId- Remove from watchlistGET /api/watchlist/check/:movieId- Check if in watchlistPOST /api/watchlist/check-multiple- Check multiple moviesDELETE /api/watchlist- Clear entire watchlistGET /api/watchlist/popular- Get popular moviesGET /api/watchlist/stats- Get watchlist statistics
- Node.js (v18+)
- PostgreSQL (v13+)
- OMDB API Key
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env
Edit
.envwith your database credentials and API keys. -
Set up PostgreSQL database:
CREATE DATABASE movieapp; CREATE USER movieapp WITH PASSWORD 'movieapp'; GRANT ALL PRIVILEGES ON DATABASE movieapp TO movieapp;
-
Initialize database schema:
npm run init-db
-
Start the development server:
npm run dev
The server will start on http://localhost:5000
The database initialization creates two default users:
- Admin:
admin@moviedb.com/admin123 - User:
user@moviedb.com/user123
- id, email, password_hash, name, role, created_at, updated_at
- id, title, year, runtime, director, cast, genre, plot, poster, imdb_rating, language, country, awards, box_office, created_by, created_at, updated_at
- id, user_id, movie_id, movie_source, title, content, rating, helpful_count, total_votes, created_at, updated_at
- id, user_id, movie_id, movie_source, movie_data, created_at
The system seamlessly blends two movie sources:
- OMDB API Movies: External movie database with rich metadata
- Custom Database Movies: Movies added by admins via the admin panel
- Search: Queries both OMDB and custom database, returns combined results
- Movie Details: Handles both OMDB IDs and custom movie IDs
- Reviews & Watchlists: Support both movie types via
movie_sourcefield
- OMDB Movies: Use original OMDB ID (e.g., "tt0468569")
- Custom Movies: Prefixed with "custom_" (e.g., "custom_1")
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcrypt with configurable rounds
- Rate Limiting: 100 requests per 15 minutes per IP
- Input Validation: Comprehensive validation using express-validator
- CORS: Configured for frontend domain
- Helmet: Security headers
- SQL Injection Protection: Parameterized queries
See .env.example for all required environment variables.
npm run init-db- Initialize database schema and default users- Database connection details in
src/database/connection.js
Use tools like Postman or curl to test the endpoints. Include the JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Set
NODE_ENV=production - Use secure JWT secrets
- Configure production database
- Set up SSL/TLS
- Use process manager (PM2)
- Set up reverse proxy (Nginx)