Your full-stack application boots up smoothly in the Replit development workspace. The preview loads, API calls return 200 OK, and database queries succeed. Then you hit Deploy. Minutes later, the production container crashes on boot with KeyError or undefined, or worse, your database credentials fail silently.
At 365Finds, we see developers hit this exact wall constantly. The culprit is rarely broken application code. It is an architectural mismatch: Replit strictly isolates the development editor workspace from production deployments, and modern full-stack architectures split client bundles from server runtimes. If you configure secrets in only one layer, your deployment will fail.
Here is the exact method 365Finds uses to configure, secure, and verify environment variables and secrets on Replit across both development and live production environments.
The Three-Way Variable Architecture on Replit
Before adding a single key, you need clarity on where Replit stores data. Replit divides project configuration into three distinct tiers:
- Workspace Secrets (Development Store): Accessed via the Secrets tool (the lock icon in the left workspace tools dock). These values are encrypted using AES-256 at rest and transmitted over TLS. Replit injects them dynamically as system environment variables into your interactive development container. They are never committed to your Git history or exposed when another user forks a public Repl.
- Workspace Configurations (Non-Sensitive): Also located in the Secrets pane, but explicitly separated. These store public settings like log levels (
LOG_LEVEL=debug), feature flags, or ports. They provide environment-specific behavior without encryption overhead. - Deployment Secrets & Environment Variables (Production Store): This is where most developers trip up. Workspace secrets do not automatically update live production deployments. When you deploy an application, Replit provisions an isolated production container (backed by Google Cloud Platform). Production containers pull variables from the Deployment configuration panel, not from your active editor session.
| Variable Category | Storage Location | Encryption | Client vs. Server Scope | Typical Use Cases |
|---|---|---|---|---|
| Workspace Secrets | Editor Tools > Secrets | AES-256 at rest | Server-side runtime only | Dev database URI; test Stripe keys; local JWT secret |
| Workspace Config | Editor Tools > Secrets (Config tab) | Standard metadata | Server-side runtime | PORT=5000; NODE_ENV=development; debug flags |
| Deployment Secrets | Deploy Tab > Settings > Environment Variables | Encrypted production store | Server-side production runtime | Production PostgreSQL URI; live Stripe secret key; webhook secrets |
| Public Client Variables | Bundled during build (.replit or deployment step) | None (Publicly visible in browser) | Browser frontend bundle | VITE_API_URL; NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY |
The Full-Stack Hazard: Server Secrets vs. Client Bundles
In a full-stack architecture—such as an Express or FastAPI backend paired with a React, Vite, or Next.js frontend—a critical boundary exists between server execution and client execution.
1. Server-Side Secrets Stay on the Server
Server environments read secrets directly from the operating system runtime:
- Node.js / Express:
process.env.DATABASE_URL - Python / FastAPI / Flask:
os.environ.get("DATABASE_URL")
These variables never reach the browser. They stay inside the Replit container.
2. Client-Side Variables Are Embedded in Public Code
Frontend build tools (Vite, Webpack, esbuild, Next.js) compile code into static JavaScript, HTML, and CSS bundles. If you pass an environment variable to the frontend, that variable is baked directly into plaintext JavaScript files delivered to every visitor.
- Vite will only expose variables prefixed with
VITE_(e.g.,import.meta.env.VITE_SUPABASE_ANON_KEY). - Next.js will only expose variables prefixed with
NEXT_PUBLIC_(e.g.,process.env.NEXT_PUBLIC_API_URL).
365Finds considers this the single most dangerous mistake on Replit: developers often name their secret VITE_OPENAI_API_KEY so their frontend React component can call OpenAI directly. Never do this. Anyone can open Chrome DevTools, inspect the JavaScript bundle or network requests, and steal your billing API key. All sensitive API calls must route through your backend server routes on Replit.
3. Deployment Type Dictates Secrets Support
Replit offers four deployment types: Autoscale, Reserved VM, Static, and Scheduled.
If your full-stack app requires server secrets (like an active database pool or third-party secret tokens), you cannot use a Static Deployment. Static deployments serve pre-built static files without a backend server process. For full-stack applications, 365Finds strongly recommends Autoscale for HTTP web applications, or Reserved VM if your application maintains persistent WebSocket connections or background workers.
Step-by-Step: Configuring Secrets for Full-Stack Deployments
Step 1: Populate Secrets in the Project Editor
- In your Replit project workspace, locate the Tools sidebar on the left.
- Select Secrets (represented by a lock icon).
- Under the Secrets tab, click New Secret.
- Enter your key and value:
- Key:
DATABASE_URL - Value:
postgresql://user:password@ep-sample-pool.neon.tech/neondb
- Key:
- Repeat for all backend credentials (
SESSION_SECRET,OPENAI_API_KEY,STRIPE_SECRET_KEY). - If you have public build configurations, add them under the Configurations tab (e.g.,
NODE_ENV=development).
Rule from 365Finds: Never create a
.envfile manually in the Replit file tree if your Repl is public. Even in private Repls, manual.envfiles risk accidental Git commits. Use Replit's native Secrets manager exclusively.
Step 2: Configure Build and Run Commands in .replit
Your .replit configuration file defines how your application compiles and launches. A typical full-stack setup must build the client assets first, then start the production HTTP server.
Example .replit configuration:
modules = ["nodejs-20"]
run = "npm run build && npm run start"
[deployment]
run = ["npm", "run", "start"]
build = ["npm", "run", "build"]
deploymentTarget = "autoscale"
In your package.json, ensure the build step produces the production assets:
{
"scripts": {
"dev": "tsx server/index.ts",
"build": "vite build && esbuild server/index.ts --platform=node --packages=external --bundle --outdir=dist",
"start": "NODE_ENV=production node dist/index.js"
}
}
Step 3: Configure Deployment Environment Variables
When you click Deploy in the top right corner of Replit:
- Select Autoscale Deployment.
- Navigate to the Settings or Environment Variables section inside the deployment setup window.
- Replit will show options to sync variables from your workspace Secrets.
- Audit and split your environments:
- Do not use your development database credentials in production. Replace the dev
DATABASE_URLwith your production database cluster string. - Swap sandbox API keys (like
sk_test_...) with live production keys (sk_live_...). - Verify that every server variable consumed in your code is present in the deployment list.
- Do not use your development database credentials in production. Replace the dev
- Click Deploy.
How to Update Secrets on a Live Deployment
A frequent source of confusion is updating a secret after launch.
If you open the workspace Secrets tool and change OPENAI_API_KEY, your live deployment will NOT receive the new key. The production deployment runs inside an immutable snapshot container.
To update secrets on a live deployment:
- Open the Deployments tool from the left navigation dock.
- Click on your active deployment.
- Open Settings > Environment Variables.
- Update the key value directly in the deployment settings.
- Click Redeploy (or publish a new release). Replit will trigger a rolling restart of your production containers, injecting the updated environment variables during the boot sequence.
365Finds Deployment Checklist
Before marking your Replit full-stack project complete, verify these checkpoints:
- Client Bundle Scan: Open your live deployed site, inspect
dist/or bundled assets in DevTools, and search for the string_KEYor_SECRET. If any private token appears in plain text, your client build leaked backend secrets. - Fallback Handling: In your backend startup logic, assert critical environment variables before launching the server:
const requiredEnv = ['DATABASE_URL', 'SESSION_SECRET']; for (const key of requiredEnv) { if (!process.env[key]) { console.error(`FATAL: Missing required environment variable: ${key}`); process.exit(1); } } - Database Connection Limits: In an Autoscale deployment on Replit, multiple container instances spin up to handle traffic spikes. Ensure your production
DATABASE_URLconnects through a connection pooler (such as PgBouncer or Neon's pooled endpoint) to prevent container auto-scaling from exhausting database connection limits.