Replit is an unmatched playground for turning an idea into a functional full-stack prototype in twenty minutes. Especially with Replit Agent, spinning up a React frontend, an Express backend, and a provisioned PostgreSQL database feels like pure magic. But when traffic climbs, Replit’s compute unit costs start compounding, or enterprise compliance demands dedicated infrastructure, you hit a wall: Replit does not offer a single "Export to Production" button.
At 365Finds, we have dissected full-stack applications built inside Replit to map out the cleanest exit paths. Migrating off Replit is entirely feasible, but naive attempts often fail because developers treat it like a simple Git clone. A Replit project is an intertwined system of code, encrypted secrets, managed databases, and proprietary Nix runtimes.
This guide walks you through every step of detaching your full-stack app from Replit, exporting it to GitHub, sanitizing the codebase, migrating the database, and running it inside a production-ready Docker container on any self-hosted server.
The Ejection Reality: What Moves and What Stays Behind
Before touching a terminal, understand the boundary line between what Replit exports and what it keeps locked in its cloud.
| Component | Can It Be Exported via Git? | Where It Lives / How to Extract |
|---|---|---|
| Source Code & Assets | Yes | Synced via Git pane or downloaded as ZIP |
| Git History & Milestones | Yes | Preserved in the repository .git tree |
| Secrets & API Keys | No | Stored in Replit Secrets; must be manually copied to .env |
| PostgreSQL Database | No | Hosted on Replit managed infrastructure; dump via pg_dump |
| Native Dependencies | No | Defined in replit.nix; must be rebuilt via Docker or system packages |
| Replit Auth & Key-Value | No | Proprietary runtime hooks; requires code-level refactoring |
If you simply run git push origin main, your remote repository will lack environment variables, contain an empty database connection string, and crash the moment you run npm start on an independent machine.
Step 1: Exporting Source Code to a Standard Git Repository
Replit supports native Git workflows, making code extraction straightforward. You can push your project to GitHub, GitLab, or any remote repository.
Method A: Using the Replit Git Pane (Recommended)
- Open your project in the Replit workspace.
- In the left-hand navigation bar, click the Tools icon and select Git (or open the Git pane).
- If your account is not connected, click Connect to GitHub and authorize the integration.
- Click Create GitHub Repository (or paste an existing remote URL under remote settings).
- Stage all untracked and modified files, enter an initial commit message such as
chore: export codebase from Replit, and click Push.
Method B: Using the Replit Shell
If you prefer explicit CLI control, open the Shell tab in the bottom panel:
# Verify git status inside Replit
git status
# Add your remote Git repository
git remote add origin https://github.com/your-username/your-replit-app.git
# Set the default branch and push
git branch -M main
git push -u origin main
365Finds caution: If you choose to download your code via Workspace Menu > Download as ZIP instead of Git, Replit strips the
.gitfolder. You will lose the revision history and Agent checkpoint commits. Always prefer Git sync.
Step 2: Extracting and Sanitizing Environment Variables
Because Replit encrypts secrets separately from repository files, none of your credentials will exist in your new Git repository.
- In the Replit Project Editor, open Tools > Secrets.
- Copy every key-value pair into a local file named
.envin your root directory. - Clean out Replit-internal environment variables that are injected automatically at runtime. Delete or ignore:
REPL_IDREPL_SLUGREPL_OWNERREPLIT_DOMAINSREPLIT_DB_URL(unless migrating legacy key-value data)
- Ensure
.envis listed in your.gitignorefile before committing anything new.
Step 3: Migrating the Database
Most modern full-stack apps generated on Replit use PostgreSQL (backed by Neon on newer stacks or Helium on legacy instances) managed via Drizzle ORM or Prisma. The database runs on Replit's cloud infrastructure, not your local server.
1. Dump Data from Replit
Open the Replit Shell and extract your full database schema and data using pg_dump:
# Check that DATABASE_URL is present
echo $DATABASE_URL
# Export the entire database into a SQL script
pg_dump "$DATABASE_URL" --no-owner --no-acl -F p -f replit_backup.sql
The file replit_backup.sql will appear in your project file tree. Download it to your local machine by right-clicking the file and selecting Download, then delete the dump file from the Replit workspace so credentials are not stored in plaintext.
2. Provision and Restore to a New Database
You can restore this backup to any standard PostgreSQL 15+ or 16+ instance, such as a local PostgreSQL container, Supabase, Neon, Railway, or managed AWS RDS.
# On your local machine or destination server
psql "postgresql://user:password@localhost:5432/myapp" < replit_backup.sql
If your application uses Drizzle ORM (the standard for Replit Agent full-stack apps), you can alternatively generate fresh schema tables directly against your target database using your schema definition files:
# In your local project directory, update DATABASE_URL in .env
npm run db:push
3. Replacing Legacy @replit/database
If your project was built before PostgreSQL became default and uses Replit's legacy Key-Value store (@replit/database), that package makes HTTP calls directly to Replit's internal KV service. It will throw connection timeouts outside Replit. You must rewrite those operations using Redis (ioredis) or SQLite (better-sqlite3).
Step 4: Refactoring Replit-Specific Code and Runtimes
Replit injects specific assumptions into how apps listen for network requests and handle authentication. Before running self-hosted, address these three common snags:
1. Port and Host Bindings
Replit projects often bind to 0.0.0.0 with arbitrary fallback ports. Ensure your server entrypoint (e.g., server/index.ts) respects the standard PORT variable:
const PORT = parseInt(process.env.PORT || "5000", 10);
const HOST = "0.0.0.0";
app.listen(PORT, HOST, () => {
console.log(`Server running on http://${HOST}:${PORT}`);
});
2. Decoupling Replit Auth
If your Replit app leveraged Replit's built-in authentication headers (X-Replit-User-Id, X-Replit-User-Name, or the @replit/repl-auth library), these headers will be missing in self-hosted environments, causing requests to fail or return null.
At 365Finds, we recommend replacing Replit Auth with a self-hosted session library (such as express-session with a PostgreSQL session store like connect-pg-simple) or managed auth services like Clerk or Supabase Auth.
3. Replacing Nix Configuration
Replit uses replit.nix and .replit to install native packages (like pkgs.ffmpeg, pkgs.postgresql, or Python headers). In a standard Linux or Docker environment, Nix is not required. You can safely discard replit.nix once you identify the system packages your app needs, moving them into standard apt-get or Docker instructions.
Step 5: Containerizing for Self-Hosting (Docker Setup)
The cleanest, most resilient way to run a migrated Replit application on a VPS (such as Hetzner, DigitalOcean, or Linode) is with a multi-stage Dockerfile and docker-compose.yml.
The Dockerfile
Create a Dockerfile at the root of your project:
# Stage 1: Build Frontend and Backend
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: Production Runner
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=5000
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=builder /app/dist ./dist
# If you have shared schema or server scripts
COPY --from=builder /app/server ./server
EXPOSE 5000
CMD ["npm", "start"]
The docker-compose.yml
Pair the app with a self-hosted PostgreSQL database:
version: "3.8"
services:
app:
build: .
restart: always
ports:
- "5000:5000"
environment:
- NODE_ENV=production
- PORT=5000
- DATABASE_URL=postgresql://appuser:securepassword@db:5432/appdb
- SESSION_SECRET=replace_this_with_a_secure_random_string
depends_on:
db:
condition: service_healthy
db:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_USER: appuser
POSTGRES_PASSWORD: securepassword
POSTGRES_DB: appdb
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
interval: 5s
timeout: 5s
retries: 5
volumes:
postgres_data:
Run the stack locally or on your self-hosted server:
docker compose up -d --build
Add a lightweight reverse proxy like Caddy or Nginx in front of port 5000 to manage automated Let's Encrypt SSL certificates and domain routing.
365Finds Institutional Take: When to Migrate vs. When to Stay
Replit is an extraordinary platform for zero-to-one product velocity. At 365Finds, we build quick internal prototypes on it regularly. However, the economics and infrastructure constraints shift abruptly as soon as a project gains traction:
- Stay on Replit if your app is an internal dashboard used by 10 people, an exploratory proof of concept, or if your team lacks anyone willing to manage a Linux server or Docker deployment. Replit Deployments handle high availability without DevOps friction.
- Migrate to Self-Hosted when your database needs specialized extensions, your storage volume expands, your monthly compute unit spend exceeds $40–$60, or data privacy rules forbid hosting customer information on Replit's shared multi-tenant infrastructure.
The migration takes roughly two to four hours for a standard full-stack application. Once wrapped in Docker, you regain full ownership of your code, your secrets, and your database.