Many applications need runtime configuration like API keys, database URLs, or feature flags. prev lets you inject environment variables into your preview containers at deploy time.
Availability
Environment variables are available on all plans.
Using --env Flags
Pass individual environment variables with the -e / --env flag. The flag is repeatable:
prev create . -e NODE_ENV=production -e API_KEY=sk-abc123
With Docker Images
prev create --image postgres:16 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=myapp
Using Env Files
Point to a specific env file with --env-file:
prev create . --env-file .env.staging
Auto-Detection
For local deployments, prev automatically reads a .env file from your project root if one exists. No flags needed:
# If ./my-app/.env exists, it's automatically loaded
prev create ./my-appAuto-detection does not apply to --image deployments. Use --env or --env-file explicitly for Docker image deploys.
Precedence
When multiple sources provide the same variable, the highest-priority value wins:
--env KEY=VALUEflags (highest priority)--env-fileor auto-detected.env
This lets you override specific values from your env file:
# .env has NODE_ENV=development, but we override it
prev create . -e NODE_ENV=production
Env File Format
The env file parser supports standard .env syntax:
# Comments are ignored
DATABASE_URL=postgres://user:pass@host/db
API_KEY=sk-abc123
NODE_ENV=production
# Quoted values (quotes are stripped)
SECRET="my secret value"
GREETING='hello world'
Examples
Node.js App with API Keys
prev create . -e NODE_ENV=production -e STRIPE_KEY=sk_test_xxx -e DATABASE_URL=postgres://...
Python App with Config
prev create . --env-file .env.preview -e DEBUG=false
In-Place Update with Env Vars
prev create --to my-demo . -e FEATURE_FLAG=true
Security Notes
- Environment variables are injected at container runtime — they are not stored in the prev API database
- Variables are transmitted over HTTPS (SSL is always enabled)
- Avoid committing
.envfiles with real secrets to version control - For shared teams, consider using
--env-filewith a file not checked into git