Overview
Popcorn Vision uses environment variables to configure API connections, image CDN endpoints, and analytics. All configuration is managed through a.env.local file in your project root.
Quick Setup
Add your TMDB credentials
Fill in your TMDB API key and Read Access Token (see TMDB API Setup for details)
Required Variables
These variables are essential for Popcorn Vision to function properly.API Configuration
The base URL for the TMDB API v3 endpoint.Default value:
https://api.themoviedb.org/3You should not need to change this unless TMDB changes their API endpoint structure.
Your TMDB API key (v3 auth).Used for server-side API requests to TMDB. This is required for authentication, account management, and fetching movie/TV show data.Where to get it: TMDB API Settings
Your TMDB Read Access Token (v4 auth).Some TMDB API features require the v4 Read Access Token instead of the API key. While not currently heavily used in the codebase, it’s recommended to provide both for full compatibility.Where to get it: TMDB API Settings (under API Read Access Token)
Image CDN Configuration
TMDB provides a CDN for movie posters, backdrops, and profile images. These variables configure the different image sizes used throughout the application.All image URLs use the
NEXT_PUBLIC_ prefix, making them accessible in client-side code for optimal performance.Ultra-small image size (45px width) for thumbnails.Default:
https://image.tmdb.org/t/p/w45Extra-small image size (92px width) for small thumbnails.Default:
https://image.tmdb.org/t/p/w92Small image size (154px width) for compact views.Default:
https://image.tmdb.org/t/p/w154Small-medium image size (185px width) for profile pictures.Default:
https://image.tmdb.org/t/p/w185Medium image size (300px width) for cards and listings.Default:
https://image.tmdb.org/t/p/w300Medium-large image size (342px width) for poster displays.Default:
https://image.tmdb.org/t/p/w342Large image size (500px width) for featured content.Default:
https://image.tmdb.org/t/p/w500Extra-large image size (632px width) for detailed views.Default:
https://image.tmdb.org/t/p/w632HD image size (780px width) for backdrops.Default:
https://image.tmdb.org/t/p/w780Full HD image size (1280px width) for hero sections.Default:
https://image.tmdb.org/t/p/w1280Original uncompressed image size for maximum quality.Default:
https://image.tmdb.org/t/p/originalOptional Variables
These variables enable additional features but are not required for basic functionality.Google Analytics 4 Measurement ID for tracking user behavior and analytics.Format:
G-XXXXXXXXXXExample: G-12345ABCDEIf not provided, Google Analytics tracking will be disabled.Where to get it: Google Analytics - Create a GA4 property and copy the Measurement IDExample Configuration
Here’s a complete example.env.local file with all variables configured:
Security Best Practices
Never commit secrets to version control
Never commit secrets to version control
Always add Only commit
.env.local, .env.production, and .env.development to your .gitignore file:.gitignore
.env.example with placeholder values.Use different credentials for development and production
Use different credentials for development and production
Consider creating separate TMDB API keys for development and production environments. This helps you:
- Track API usage separately
- Revoke compromised keys without affecting production
- Apply different rate limits per environment
Rotate API keys periodically
Rotate API keys periodically
Regularly rotate your TMDB API credentials, especially if:
- They may have been exposed in logs or error messages
- A team member with access leaves the project
- You suspect unauthorized access
Use platform environment variables in production
Use platform environment variables in production
When deploying to platforms like Vercel or Netlify, use their built-in environment variable management instead of committing
.env files. See Deployment Configuration for details.Troubleshooting
Images not loading
Images not loading
Problem: Movie posters and backdrops are not displaying.Solutions:
- Verify all
NEXT_PUBLIC_API_IMAGE_*variables are set correctly - Check browser console for CORS errors
- Ensure the URLs match TMDB’s current CDN structure
- Clear your browser cache and restart the dev server
API authentication errors
API authentication errors
Problem: Getting 401 Unauthorized errors from TMDB API.Solutions:
- Double-check your
API_KEYis correct (copy it fresh from TMDB) - Ensure there are no extra spaces or quotes in your
.env.localfile - Verify your TMDB API key is active in your account settings
- Restart your development server after changing environment variables
Environment variables not updating
Environment variables not updating
Problem: Changes to
.env.local are not taking effect.Solution:
Next.js loads environment variables at build time. After changing any variable:Variables undefined in client-side code
Variables undefined in client-side code
Problem: Environment variables are
undefined in React components.Solution:
Only variables prefixed with NEXT_PUBLIC_ are accessible in client-side code. Server-only variables (like API_KEY) are intentionally not available in the browser for security.If you need a variable in both places, you must create two versions:API_KEYfor server-sideNEXT_PUBLIC_API_KEYfor client-side (only if absolutely necessary)
Next Steps
TMDB API Setup
Get your TMDB API credentials and configure authentication
Deployment
Deploy your Popcorn Vision instance to production