Deployment
Backend Deployment
A step-by-step guide to deploy a ready-to-use NestJS backend on Railway, set environment variables, and retrieve the backend URL for frontend integration.
Setup Instructions for Railway
1. Create a Railway Project and Deploy the Backend
- Go to railway.app and log in.
- Click on Start a New Project β Deploy from GitHub.
- Connect your GitHub repository containing the NestJS backend.
- Railway will automatically:
- Install dependencies,
- Build the project,
- Start the app (no configuration in
package.jsonis required).
2. Set Environment Variables
To transfer the environment variables from your local .env file:
- Open your
.envfile locally. - Go to your Railway project dashboard.
- Navigate to the Environment tab.
- Copy each variable from
.envand paste it into the Railway Environment panel:-
Example:
-
Important: Make sure to save the changes. Then redeploy the project with updated variables.
-
3. Retrieve the Backend Public URL
Once the deployment is successful:
- Go to your Railway project dashboard.
- Click on the Settings tab.
- Under the Networking section, you can click the Generate Domain button and it'll generate your domain (e.g.,
your-app-name.up.railway.app). - Copy this URL β this is your backend's public endpoint.
4. Update Frontend Configuration
- Open your frontend projectβs
environment.prod.tsfile. - Replace the
apiUrlvalue with the Railway backend URL:
- Save the file and redeploy your frontend (e.g., to Netlify, Vercel, or other hosting).
π Congratulations!
Your NestJS backend is now live on Railway, and the frontend is configured to communicate with it. π
Troubleshooting Tips
- Logs: If something goes wrong, check the Logs tab in Railway for any errors.
- Environment Variables: Ensure all required variables from
.envare set in Railway.
Now everything is deployed and connected β your frontend can seamlessly interact with the backend! π