Deploying Strapi 4 to Railway
Tags: strapi, railway, cloudinary, cms
Published: 2022-08-03 21:20:36

---
title: Deploying Strapi 4 to Railway
published: true
description: Step by step on how to deploy Strapi 4 to Railway
tags: strapi, railway, cloudinary, cms
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk2hv3fb9qohcgdgqt5h.png
--- 

## What is Strapi?

[Strapi](https://strapi.io/) is an open-source headless Content Management System that offers you the chance to develop API with distinctive features. It's built on Node.js and works with any GraphQL enabled Frontend Frameworks.

You can create custom content types, relationships and media libraries for images and audio files with Strapi.

## What is [Railway](https://railway.app/)?

It's a PaaS (similar to Heroku) that allows you to connect your Git repository and with each commit or new PR you trigger an event to deploy your application. Railway has several very nice features:

- Uses [NixPacks](https://github.com/railwayapp/nixpacks) to build the images;
- Free SSL Certificate;
- Straightforward UI;
- Create multiple environments;
- "Pay as you grow";

However, there are some features I wish it had:

- More regions available - :brazil: please ([See the thread](https://feedback.railway.app/feature-requests/p/configurable-deployment-region));
- Access the application console via UI (Similar to Digital Ocean and Render);


## Deploy

Create your account and create a new project

![Creating a new project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urq6ame4u4ftdoygo4y8.png)
 
Search by `Strapi` and select the first option.

![Selecting the Strapi option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mshbvm5z2fqsrhr6x6l6.png)

Add a valid name for your repository. 

![Adding environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dyfrxjtwge7f2tklmneh.png)

The railway will copy a [project](https://github.com/candidosales/strapi-railway-deploy) into your account during the deployment process. As shown in the image below, you will have to add the environment variables.


![The project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a1typb8q63hwolb4tswz.png)
 

You can use the [https://randomkeygen.com/](https://randomkeygen.com/) to fill up the `ADMIN_JWT_SECRET`,`JWT_SECRET `, `APP_KEYS` and `API_TOKEN_SALT`.



In that [project](https://github.com/candidosales/strapi-railway-deploy) is set up the Strapi with Postgres and [Cloudinary](https://cloudinary.com/). Cloudinary is responsible for managing your media library, so you must have a [Cloudinary](https://cloudinary.com/) account.

In the Cloudinary, you copy your credentials.

![Cloudinary Credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/be6y46tgvc1i12mzhtzw.png)

Then paste it into the Railway Environment variables and click on `Deploy`.

![Railway Environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/futxbb1p075rse1ytsr3.png)
  
Waiting the building and deploy!

![Building](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9jd63xw7i3vd7008f7m.png)

It's done! 

![Deployed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ey8h5cab4eopsd2ev88.png)
 

Now you can access the Strapi admin via your `https://strapi-production-XXXX.up.railway.app/admin` and create a user account.


## Troubleshooting

One annoying thing about Strapi is that it doesn't have **development mode** enabled by default, so I can't create new collections.

![Can't create new collections](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nt2pxg51gfxr16hypm9z.png)

I wasted a lot of time thinking that changing the `NODE_ENV` environment variable could solve it, but it didn't.

So I found another way to solve this.

An important thing to note: the current version deployed is `v4.1.9`.

![v4.1.9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ozcw4spk12lrxa63y5i.png)

To enable **development mode** and update the project we need to make a change to the project created by Railway in your Github account.

Change the file `package.json` to be like this:

```json
{
  "name": "strapi",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi develop", // <<----- Here
    "build": "strapi build",
    "strapi": "strapi"
  },
  "devDependencies": {},
  "dependencies": {
    "@strapi/plugin-i18n": "4.1.9", // Upgrade to 4.3.2
    "@strapi/plugin-users-permissions": "4.1.9", // Upgrade to 4.3.2
    "@strapi/provider-upload-cloudinary": "4.1.9", // Upgrade to 4.3.2
    "@strapi/strapi": "4.1.9", // Upgrade to 4.3.2
    "pg": "8.7.3"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "35d7a084-3088-4d0b-869e-f503693ee8e5"
  },
  "engines": {
    "node": ">=12.x.x <=16.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}
```

To start Strapi in **development mode**, I changed the value for `strapi develop` in the command start.

⚠️ Don't forget to run `yarn install` to update the `yarn.lock` before pushing your commit.

You can see my commit here: https://github.com/candidosales/strapi-railway-deploy/commit/529cb16521f33a5d824a34a1de3f30868b122ff7

After pushing the commit, the build will start again and when finished ... 

![Deployed!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y6bzrc1n712g6iepjdu5.png)
 

You can verify that it will be in the new version, and you can create new collections.

![v4.3.2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/se9ms0qjvnsad9502hau.png)

![Enable to create collections](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khk23qcjro3mdxnsavxr.png)

----------

If you want to have more control over the media gallery and don't want to deploy using Cloudinary, in the following article, I'll teach you how to deploy Strapi 4 to [Render](https://render.com/).

Any feedback is welcome! 😄