DevRocket
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

  1. Go to railway.app and log in.
  2. Click on Start a New Project β†’ Deploy from GitHub.
  3. Connect your GitHub repository containing the NestJS backend.
  4. Railway will automatically:
    • Install dependencies,
    • Build the project,
    • Start the app (no configuration in package.json is required).

2. Set Environment Variables

To transfer the environment variables from your local .env file:

  1. Open your .env file locally.
  2. Go to your Railway project dashboard.
  3. Navigate to the Environment tab.
  4. Copy each variable from .env and paste it into the Railway Environment panel:
    • Example:

      NODE_ENV=production
      PORT=3000
      JWT_SECRET=your-jwt-secret
      DATABASE_URL=your-database-url
    • 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:

  1. Go to your Railway project dashboard.
  2. Click on the Settings tab.
  3. 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).
  4. Copy this URL – this is your backend's public endpoint.

4. Update Frontend Configuration

  1. Open your frontend project’s environment.prod.ts file.
  2. Replace the apiUrl value with the Railway backend URL:
export const environment = {
  production: true,
  apiUrl: 'https://your-app-name.up.railway.app', // Replace with your backend URL
};
  1. 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

  1. Logs: If something goes wrong, check the Logs tab in Railway for any errors.
  2. Environment Variables: Ensure all required variables from .env are set in Railway.

Now everything is deployed and connected – your frontend can seamlessly interact with the backend! πŸš€

On this page