Migrate from Replit to Railway
This guide covers how to move a project from Replit to Railway, including code export, environment variables, database migration, and deployment configuration.
Prerequisites
- A Railway account
- A GitHub account
- Access to your Replit project
- The Railway CLI installed (optional, but useful for database migration)
1. Export your code from Replit
Your code needs to be in a GitHub repository before you can deploy it on Railway.
If your Replit project is already connected to GitHub:
No export is needed. You will connect the same repository to Railway in the next step.
If your Replit project is not connected to GitHub:
- In Replit, open your project and click the three-dot menu in the file tree.
- Select Download as zip.
- Create a new repository on GitHub.
- Unzip the downloaded project and push the code to your new repository:
Remove the .replit and replit.nix files from your repository before pushing: Railway does not use them.
2. Create a Railway project
- Go to railway.com/new.
- Select Deploy from GitHub Repo.
- Connect your GitHub account if you have not already, then select the repository containing your code.
Railway creates a new project with a service linked to your repository. Pushes to your default branch will trigger deployments automatically.
3. Configure environment variables
Replit stores environment variables in the Secrets tab. You need to copy these into Railway.
- In Replit, open the Secrets tab and note each key-value pair.
- In Railway, click on your service and go to the Variables tab.
- Add each variable individually, or click Raw Editor to paste multiple variables at once in
KEY=VALUEformat.
After saving, Railway redeploys the service with the updated variables.
If your Replit project references a DATABASE_URL or similar connection string, update it after completing the database migration in the next step.
4. Migrate your database
Skip this step if your Replit project does not use a database.
Replit PostgreSQL to Railway Postgres
- Right-click on the Railway project canvas and select Database > Add PostgreSQL to provision a new Postgres instance.
- Export your data from Replit's PostgreSQL using
pg_dump:
- Restore the dump into your Railway Postgres instance:
You can find your Railway Postgres connection details in the Variables tab of the database service.
- Update the
DATABASE_URLvariable in your app service to reference the Railway Postgres instance. You can use the reference variable${{Postgres.DATABASE_URL}}to keep the value in sync automatically.
For more detail, see PostgreSQL on Railway.
Replit Database (key-value) to Railway Redis
Replit Database is a key-value store. If your project uses it, you can migrate to a Redis instance on Railway.
- Write a script in your Replit project to export all keys and values from Replit Database to a JSON file:
- Provision a Redis instance in Railway by right-clicking on the project canvas and selecting Database > Add Redis.
- Write a script to import the JSON data into Redis:
- Update your application code to use Redis instead of
replit.db.
5. Configure builds and deployments
Replit uses the .replit file to define run commands and language settings. Railway uses Railpack for build detection and does not read .replit files.
Automatic detection: Railpack detects your project type from standard files:
- Node.js:
package.json(readsscripts.startfor the start command) - Python:
requirements.txtorpyproject.toml - Go:
go.mod
If Railpack detects your project correctly, no configuration is needed.
Custom build or start commands: If you need to override the defaults, go to your service's Settings tab and set the Build Command and Start Command fields.
Dockerfile: If your project requires a custom build environment, you can add a Dockerfile to your repository. Railway detects and uses it automatically.
6. Set up a public domain
Replit provides .replit.app domains. On Railway, you can generate a .up.railway.app domain or configure a custom domain.
- Click on your service in the project canvas.
- Go to the Settings tab.
- Under Networking > Public Networking, click Generate Domain to get a
.up.railway.appdomain.
To use a custom domain, see Custom Domains.
Migration checklist
- Code exported to GitHub
-
.replitandreplit.nixfiles removed from the repository - Environment variables migrated
- Database migrated (if applicable)
- Build and start commands verified
- Public domain configured
- Application tested