Overview
Environment File Setup
Beat App includes a.env.example file with all required variables:
Available Variables
All environment variables in Beat App must be prefixed withVITE_ to be accessible in the frontend code.
VITE_API_URL
The base URL for the Beat App API backend.Default:
http://localhost:3000Examples:- Development:
http://localhost:3000 - Production:
https://api.beatapp.com - Docker:
http://beat-api:3000
This URL is used by the frontend to make API requests for track data, album information, and artist details.
VITE_YOUTUBE_API_TOKEN
YouTube API authentication token for fetching music data.Default:
your_token_hereWhere to get it:- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the YouTube Data API v3
- Create credentials (API Key)
- Copy the API key to this variable
Environment File Structure
Here’s the complete.env.example file:
Development vs Production
Development
For local development, create a.env file in the project root:
.env
Production
For production deployments, you have several options:How Vite Processes Environment Variables
Vite exposes environment variables to your source code viaimport.meta.env:
Only variables prefixed with
VITE_ are exposed to the client-side code. This prevents accidentally exposing server-side secrets.Docker Environment Variables
Thedocker-compose.yml configuration passes environment variables as build arguments:
.env file in the same directory as docker-compose.yml.
Security Best Practices
Do’s
- Use environment variables for configuration (URLs, feature flags)
- Use API tokens that are scoped for frontend/public use only
- Rotate API keys regularly
- Use different tokens for development and production
Don’ts
- Never store private keys or secrets in frontend environment variables
- Never commit
.envfiles to version control - Don’t use admin-level API tokens in the frontend
- Don’t assume environment variables are hidden from users
Troubleshooting
Variables not defined
Ifimport.meta.env.VITE_API_URL returns undefined:
- Verify the variable name starts with
VITE_ - Ensure the
.envfile is in the project root - Rebuild the application (
npm run buildordocker-compose up -d --build) - Check that the
.envfile is not ignored by.gitignore
Changes not reflecting
Environment variables are embedded at build time:Docker not reading .env
Ensure your.env file is in the same directory as docker-compose.yml:
Multiple Environments
Vite supports multiple environment files:Files like
.env.local are excluded by .dockerignore and .gitignore. Use .env for Docker deployments.