Overview
Environment variables allow you to store configuration values and secrets that your application needs to run. Common use cases include:- API keys and tokens
- External service credentials
- Feature flags
- Environment-specific configuration
Deployment Targets
Each environment variable can be configured for one or more deployment targets:Sandbox
The development environment where you build and test your application. When you modify sandbox environment variables, the dev server automatically restarts to apply the changes.Preview
Branch preview deployments that are created for specific Git branches. Use preview variables to test with production-like data without affecting your live site.Production
Your live, published application. Production variables are used when you deploy your project to your custom domain or the defaultproject-slug.stardeck.site URL.
You can select multiple targets for a single variable, allowing you to reuse the same configuration across environments.
Variable Types
Stardeck supports two types of environment variables with different visibility and access patterns:Non-Secret Variables
Non-secret variables are suitable for non-sensitive configuration values that can be safely exposed:- Build-time access: Automatically available to Vite with
VITE_prefix during the build process - Runtime access: Available as regular environment variables
- Visibility: Values are visible (but obscured) in the project settings UI
- Use cases: Public API endpoints, feature flags, non-sensitive configuration
When you create a non-secret variable named
API_URL, Stardeck automatically makes it available as both VITE_API_URL (for client-side code) and API_URL (for server-side code).Secret Variables
Secret variables are encrypted and kept secure:- Runtime-only: Only available at runtime, never exposed during the build process
- Encrypted storage: Values are encrypted in the database
- Hidden in UI: Values are never displayed in the project settings
- Use cases: API keys, tokens, passwords, database credentials
Reserved Variables
Certain environment variable names are reserved by Stardeck for system use and cannot be set by users:Reserved Prefixes
- VITE_ - Automatically added to non-secret variables for client-side access. You should never create variables starting with
VITE_as Stardeck handles this automatically. - OIDC_ - Reserved for OAuth and authentication configuration managed by Stardeck
Reserved Names
- DATABASE_URL - Managed database connection string (automatically provided by Stardeck)
- APP_DATABASE_NAME - Application database name
- DATABASE_NAME - Database name (legacy)
- DEPLOYMENT_ID - Current deployment identifier
- CLOUDFLARE_INCLUDE_PROCESS_ENV - Cloudflare environment flag
Managing Environment Variables
Accessing the Settings
- Open your project in the Stardeck dashboard
- Click the Settings button (gear icon)
- Navigate to the Environment Variables tab
Adding a Variable
- Click Add Environment Variable
- Enter a Key in UPPERCASE_WITH_UNDERSCORES format (e.g.,
API_KEY,STRIPE_SECRET_KEY) - Enter the Value
- Toggle Secret Variable if the value contains sensitive information
- Select one or more Deployment Targets (sandbox, preview, production)
- Click Add Variable
For sandbox environments, the dev server will automatically restart to apply new environment variables.
Editing a Variable
- Click Edit on the variable you want to modify
- Update the key, value, secret status, or deployment targets
- Click Update Variable
When editing a secret variable, leave the value field empty to keep the existing secret value unchanged.
Deleting a Variable
- Click the trash icon next to the variable you want to remove
- Confirm the deletion
Using Variables in Your Code
Client-Side Code (Vite/React)
Access non-secret variables in your client-side code usingimport.meta.env:
Server-Side Code (Node.js/API Routes)
Access both secret and non-secret variables in your server code usingprocess.env:
Best Practices
Naming Conventions
- Use UPPERCASE letters with underscores:
MY_API_KEY,DATABASE_URL - Be descriptive and consistent:
STRIPE_SECRET_KEY,STRIPE_PUBLIC_KEY - Follow your team’s naming patterns
Security
- Use secrets for sensitive data: API keys, tokens, passwords, and connection strings should always be marked as secret
- Never commit secrets: Don’t store sensitive values in your Git repository
- Rotate credentials: Periodically update secret values, especially if they may have been exposed
- Limit access: Only add environment variables to the targets where they’re needed
Organization
- Group related variables: Use prefixes to organize related configuration (e.g.,
STRIPE_,AWS_) - Document variables: Keep track of what each variable is used for
- Environment parity: Use the same variable names across all targets with environment-specific values
Client-Side Variables
- Minimize client exposure: Only use
VITE_variables when the value needs to be accessible in the browser - Never expose secrets: Client-side code is visible to users, so never put sensitive data in VITE_ variables
- Validate on server: Always validate client-provided data on the server, even if you have client-side checks
Remember: Non-secret variables are automatically available with the
VITE_ prefix for client-side access. You don’t need to create separate variables.Common Patterns
API Configuration
External Database Configuration
Stardeck automatically provides
DATABASE_URL for your project’s managed database. Use EXTERNAL_DATABASE_URL or similar names for connecting to external databases.Feature Flags
Environment-Specific Configuration
Set different values for the same variable across targets:- Sandbox:
EXTERNAL_API_URL=http://localhost:8000 - Preview:
EXTERNAL_API_URL=https://api-staging.example.com - Production:
EXTERNAL_API_URL=https://api.example.com
Need help with environment variables? Contact our support team through your dashboard.