This guide describes how to set up and deploy a Medusa backend using Railway with managed PostgreSQL and Redis databases.
Prerequisites
Before you begin, make sure you have the following:
- Railway account
- GitHub account connected with Railway
- Git installed on your local machine
1. Create Project with Database Services
- Log in to Railway and click Create New Project → Empty Project.
PostgreSQL Configuration
- In your Railway project dashboard, click Create.
- Select Database → Add PostgreSQL.
- Railway will automatically create a PostgreSQL instance.
Redis Configuration
- In your Railway project dashboard, click Create.
- Select Database → Add Redis.
- Railway will automatically create a Redis instance.
2. Prepare the Medusa Project
-
Clone your MedusaJS project to your server. This guide assumes your repository has a
backenddirectory and astorefrontdirectory at the root level:git clone <your-medusa-repository-url> cd your-medusa-project -
Download the Medusa configuration file using curl:
curl -O https://raw.githubusercontent.com/u11d-com/medusa-starter/main/backend/medusa-config.ts -
Download the startup script using curl:
curl -O https://raw.githubusercontent.com/u11d-com/medusa-starter/main/backend/start.sh -
Make the startup script executable:
chmod +x start.sh -
Modify the
package.jsonfile to update the start command only:{ "scripts": { "start": "./start.sh" } } -
Add new file
railway.jsonwith content as below:{ "$schema": "https://railway.app/railway.schema.json", "build": { "builder": "NIXPACKS", "buildCommand": "yarn build" }, "deploy": { "startCommand": "yarn run start", "healthcheckPath": "/health", "restartPolicyType": "ON_FAILURE", "restartPolicyMaxRetries": 10 } } -
Commit and push your changes to GitHub.
3. Deploy on Railway
- In your Railway project dashboard, click Create.
- Select GitHub Repository.
- If you don’t see any repositories connect your GitHub account.
- Select the repository you forked.
- Railway will automatically detect your Node.js project and begin the initial deployment.
- Fulfill environments in your server instance:
REDIS_URLwith a value fromREDIS_URLCACHE_REDIS_URLwith a value fromREDIS_URLWE_REDIS_URLwith a value fromREDIS_URLEVENT_REDIS_URLwith a value fromREDIS_URLDB_NAMEwith a value fromPG_DATABASEDB_HOSTwith a value fromPG_HOSTMEDUSA_CREATE_ADMIN_USERwithtrueMEDUSA_ADMIN_EMAILwith your admin user email addressMEDUSA_ADMIN_PASSWORDwith your admin user password
- Click
Deploybutton (you should see it in the up of the canvas). - Wait for the build process to complete. This may take several minutes.
- Once deployed, your server should be available at port 8080.
5. Configure networking
-
Go to the server settings.
-
Scroll down to networking, and click
Generate Domainbutton under Public Networking. -
Copy your generated domain, and check if the backend is health:
https://<your-app>.up.railway.app/healthYou should receive a healthy response if everything is set up correctly.
Summary
You have now deployed a MedusaJS backend on Railway using managed PostgreSQL and Redis services. Your environment is configured for production with an optional admin user creation process and accessible admin panel at the /app path.