🚀Announcing Flightcontrol - Easily Deploy Blitz.js and Next.js to AWS 🚀
Back to Documentation Menu

Deploy to a Server on Railway


Jump to a Topic

If you don't have a Railway account

Sign up for an account on Railway - they have a free tier that is sufficient for small applications.

Screen Shot 2021-05-04 at 6 11 09 PM

Set up a new project

  1. Create a new project (via your Dashboard or ⌘ + / shortcut)

Screen Shot 2021-05-04 at 5 19 28 PM

  1. If a database is required, select Provision PostgreSQL (or MongoDB/MySQL/Redis - whichever flavour your app requires). Once the database is provisioned, you will see the Project Setup page.

Screen Shot 2021-05-04 at 6 01 16 PM

If a database is not required, select Deploy From Repo.

There are two ways to set up your project on Railway:

  1. Via the command line interface (CLI)
  2. Via Railway's user interface (GUI)


  1. Install Railway
npm i -g @railway/cli
# or
yarn global add @railway/cli
  1. Login to Railway
railway login
  1. Go to your project folder and link to Railway
cd /path/to/project
railway link your-project-id

The project ID is taken from the Project Setup page.

  1. Enter your required environment variables

Set the SESSION_SECRET_KEY variable to a random string of 32 characters and the PORT variable to 3000:

railway variables set SESSION_SECRET_KEY=<your_key>
railway variables set PORT=3000

Instead of setting the PORT here, you could also modify the start script in the package.json file to blitz start --port ${PORT-3000}.

Enter other environment variables that you require. The DATABASE_URL variable will be automatically set by Railway if you provision a PostgreSQL database.

Verify that the variables are set correctly via your linked project:

railway variables
  1. Change your build script in package.json to be NODE_ENV=production blitz build && blitz prisma migrate deploy so that the production DB will be migrated on each deploy

  2. Deploy your project

railway up

Once the build is successful and deployment is completed, you will receive the URL for your application that is now accessible via the internet. To get the URL, go to the Deployments section in the project's dashboard and the URL will be listed under a successful deployment.

Screen Shot 2021-05-04 at 8 49 57 PM

You may also view your app logs by running

railway logs

In order to set Railway to build + deploy automatically when you push to a branch on your GitHub repository, connect your GitHub repository by following the GUI steps below from Step 2 onward.


  1. Enter your required environment variables

Blitz requires the SESSION_SECRET_KEY variable to be set. Go to your project on the GUI, select the Variables link and enter SESSION_SECRET_KEY as the name of the variable and a random 32-key secret as its value. Click Add to add the variable.

Set a variable PORT to 3000.

Enter other environment variables that you require. The DATABASE_URL variable will be automatically set by Railway if you provision a database.

  1. Go to the Deployments section. If your project is on GitHub, you can click on Connect GitHub to deploy and connect directly to your repositories on GitHub. Otherwise, you will have to use the CLI to deploy your application.

  2. Select the repository and the branch to deploy from and click Connect + Deploy

Screen Shot 2021-05-04 at 8 55 36 PM

  1. Railway will now build and deploy your app on every push to this branch on your selected repository.

Idea for improving this page? Edit it on GitHub.