| name | replit-multi-env-setup |
| description | Configure Replit dev/staging/production environments with separate databases, secrets, and deployment tiers.
Use when setting up multi-environment deployments, managing per-environment secrets,
or implementing environment-specific Replit configurations.
Trigger with phrases like "replit environments", "replit staging",
"replit dev prod", "replit environment setup", "replit separate databases".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","replit","deployment","environments"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Replit Multi-Environment Setup
Overview
Configure development, staging, and production environments on Replit. Leverages Replit's built-in dev/prod database separation, environment-specific secrets, and deployment types. Covers the Replit-native approach (single Repl, dual databases) and the multi-Repl approach (separate Repls per environment).
Prerequisites
- Replit Core or Teams plan (deployment access)
- PostgreSQL provisioned in Database pane
- Understanding of Replit Secrets
Environment Strategy
Approach 1: Single Repl, Dual Databases (Recommended)
Replit natively provides separate development and production databases:
Workspace "Run" button → Development database
Deployed app (.replit.app) → Production database
Both use the same DATABASE_URL env var — Replit routes automatically.
No code changes needed between environments.
Approach 2: Multi-Repl (Staging + Production)
For teams that need a staging environment:
Repl 1: my-app-staging → Autoscale deployment → staging.replit.app
Repl 2: my-app-prod → Reserved VM deployment → app.example.com
Each Repl has its own:
- Secrets (different API keys per environment)
- PostgreSQL database (separate data)
- Deployment configuration
- GitHub branch (staging → staging, main → production)
Instructions
Step 1: Environment Detection
type Environment = 'development' | 'staging' | 'production';
export function detectEnvironment(): Environment {
if (process.env.REPL_DEPLOYMENT) {
if (process.env.REPL_SLUG?.()) ;
;
}
(process..) ;
env = process.. || ;
(env === ) ;
(env === ) ;
;
}
= ();
= === ;