AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Replit Environment Variables and Secrets for Full-Stack Deployments

Natalia Amaral · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

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:

  1. 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.
  2. 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.
  3. 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 CategoryStorage LocationEncryptionClient vs. Server ScopeTypical Use Cases
Workspace SecretsEditor Tools > SecretsAES-256 at restServer-side runtime onlyDev database URI; test Stripe keys; local JWT secret
Workspace ConfigEditor Tools > Secrets (Config tab)Standard metadataServer-side runtimePORT=5000; NODE_ENV=development; debug flags
Deployment SecretsDeploy Tab > Settings > Environment VariablesEncrypted production storeServer-side production runtimeProduction PostgreSQL URI; live Stripe secret key; webhook secrets
Public Client VariablesBundled during build (.replit or deployment step)None (Publicly visible in browser)Browser frontend bundleVITE_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:

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.

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

  1. In your Replit project workspace, locate the Tools sidebar on the left.
  2. Select Secrets (represented by a lock icon).
  3. Under the Secrets tab, click New Secret.
  4. Enter your key and value:
    • Key: DATABASE_URL
    • Value: postgresql://user:password@ep-sample-pool.neon.tech/neondb
  5. Repeat for all backend credentials (SESSION_SECRET, OPENAI_API_KEY, STRIPE_SECRET_KEY).
  6. If you have public build configurations, add them under the Configurations tab (e.g., NODE_ENV=development).

Rule from 365Finds: Never create a .env file manually in the Replit file tree if your Repl is public. Even in private Repls, manual .env files 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:

  1. Select Autoscale Deployment.
  2. Navigate to the Settings or Environment Variables section inside the deployment setup window.
  3. Replit will show options to sync variables from your workspace Secrets.
  4. Audit and split your environments:
    • Do not use your development database credentials in production. Replace the dev DATABASE_URL with 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.
  5. 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:

  1. Open the Deployments tool from the left navigation dock.
  2. Click on your active deployment.
  3. Open Settings > Environment Variables.
  4. Update the key value directly in the deployment settings.
  5. 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:

  1. Client Bundle Scan: Open your live deployed site, inspect dist/ or bundled assets in DevTools, and search for the string _KEY or _SECRET. If any private token appears in plain text, your client build leaked backend secrets.
  2. 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);
      }
    }
    
  3. Database Connection Limits: In an Autoscale deployment on Replit, multiple container instances spin up to handle traffic spikes. Ensure your production DATABASE_URL connects through a connection pooler (such as PgBouncer or Neon's pooled endpoint) to prevent container auto-scaling from exhausting database connection limits.

References