Environments
Learn how to organize secrets across different environments like development, staging, and production in Redenv.
Redenv supports multiple environments within a single project, allowing you to maintain separate configurations for development, staging, production, and more.
What is an Environment?#
An environment is a isolated namespace for secrets within a project. Think of it as a separate .env file, but centralized and encrypted.
Examples:
- development: Local development secrets
- staging: Pre-production testing
- production: Live application secrets
- test: CI/CD test environment
Each environment has its own complete set of secrets with independent version histories.
Creating Environments#
When you register a project, a development environment is created by default:
redenv register my-app
# Creates project "my-app" with "development" environmentTo add more environments, simply switch to them (they're created automatically):
# Switch to production (creates it if it doesn't exist)
redenv switch env productionInfo
Environments are created on-demand when you first switch to them or add secrets.
Switching Environments#
The switch env command changes your active environment:
# Switch to development
redenv switch env development
# Switch to production
redenv switch env production
# Switch to custom environment
redenv switch env qa-testingYour current environment is stored in the redenv.config.ts file:
import { defineConfig } from "@redenv/core";
export default defineConfig({
name: "my-app",
environment: "production", // Current active environment
});Info
The redenv.config.ts file tracks your local environment preference. Other team members can work in different environments simultaneously.
Managing Secrets Per Environment#
Once you've switched environments, all secret commands operate on that environment:
# Switch to development
redenv switch env development
redenv add API_KEY "sk_test_123"
redenv add DATABASE_URL "postgresql://localhost/dev_db"
# Switch to production
redenv switch env production
redenv add API_KEY "sk_live_xyz"
redenv add DATABASE_URL "postgresql://prod-host/prod_db"Now you have different values for the same key across environments:
development.API_KEY="sk_test_123"production.API_KEY="sk_live_xyz"
Using Environments in Applications#
Your application specifies which environment to load via the SDK configuration:
import { Redenv } from "@redenv/client";
const redenv = new Redenv({
project: "my-app",
environment: process.env.NODE_ENV || "development", // Dynamic!
tokenId: process.env.REDENV_TOKEN_ID!,
token: process.env.REDENV_TOKEN_KEY!,
upstash: { ... }
});Best Practice: Use process.env.NODE_ENV or a similar mechanism to automatically select the environment.
import os
from redenv import Redenv
client = Redenv({
"project": "my-app",
"environment": os.getenv("ENV", "development"), # Dynamic!
"token_id": os.getenv("REDENV_TOKEN_ID"),
"token": os.getenv("REDENV_TOKEN_KEY"),
"upstash": { ... }
})Environment Isolation#
Environments are completely isolated:
- Secrets don't overlap: Changing
API_KEYindevelopmentwon't affectproduction - Independent versioning: Each environment has its own version history
- Separate tokens: You can create environment-specific Service Tokens
Cloning Environments#
To copy all secrets from one environment to another:
# Clone production -> staging
redenv clone --from production --to stagingThis is useful for:
- Setting up new environments
- Refreshing staging with production data
- Creating test environments
Comparing Environments#
See what's different between environments:
redenv diffOutput:
🔍 Comparing "selected 1" ↔ "selected 2" for project "redenv"
🔹 Only in development
• TEST_MODE="test"
🟡 Changed
• API_KEY
selected 1: "sk_test_..."
selected 2: "sk_live_..."
• DATABASE_URL
selected 1: "postgresql://localhost/..."
selected 2: "postgresql://prod-host/..."
🟢 Same
• DEBUG
✨ Diff complete.Syncing Secrets Across Environments#
Add the same secret to multiple environments at once:
redenv syncEnvironment Naming Conventions#
Recommended:
- Use lowercase:
development, notDevelopment - Use hyphens for spaces:
qa-testing, notqa_testing - Be descriptive:
production-eu, notprod-eu(clarity over brevity)
Avoid:
- Special characters (except hyphens and underscores)
- Spaces
- Very long names
Deleting Environments#
To permanently remove an environment and all its secrets, use the drop command:
# Delete a specific environment
redenv drop env staging
# Delete multiple environments
redenv drop env staging qa-testingError
This action is irreversible. All secrets and version history for the
environment will be permanently deleted. Always run redenv backup before
dropping environments.
Best Practices#
- Separate tokens per environment: Don't use the same service token for dev and prod
- Use meaningful names: Be explicit (
production, notprod) - Backup before major changes:
redenv backupbefore cloning or bulk operations