Deploy a Strapi Application to Heroku

Daniel Phiri
InstructorDaniel Phiri
Share this video with your friends

Social Share Links

Send Tweet

Now that we've got a functioning application it's time to deploy. For Strapi, we'll use Heroku to deploy for production. To do so we will need to create a production environment file for database.js and server.js, then we log into Heroku and created a new app. Once logged in we will set all the environment variables in Heroku. Finally, we pushed our code to Heroku and saw our application running live on the web.

Instructor: [0:00] We want to deploy our Strapi application to Heroku. To start, we'll open up VS Code. In our package.json, we'll change the node engine range to 16.x to avoid any issues with our deployment and save.

[0:15] Next up, in our config folder, we want to create a new folder called env. Inside the env, we'll create another new folder called production. Inside production, we'll create a new file called database.js. We'll paste the following configuration in it.

[0:35] Next up, in our production folder, we'll create a new file called server.js and we'll paste the following configuration in it. We'll go to our terminal and stop our server and install PG and TG connection string. Then in our VS Code, we'll open our Git Ignore and scroll to the bottom, paste package lock json, and save.

[1:05] Now that we've modified our files, we go back to our terminal and say get in it, git add, and we make a commit. We already have Heroku installed. What we do is Heroku login. Now that I'm logged in, I can type Heroku create and this creates a new application for me.

[1:29] I'll add a Postgres add-on and get my database config. Next, I set environment variables critical to Strapi working. I set my app keys, my admin token salt, my admin JWT secret, my JWT secret, my Heroku URL, my Node environment, my transfer token salt, my Cloudinary name, Cloudinary key, and Cloudinary secret.

[1:53] I then run a git push Heroku admin and this builds my project and deploys it. Once the deploy is done, you can open up your application with Heroku open. Go to my admin and create a new user and get started.

[2:55] Now, we have our app with our content type deployed to Heroku. That is how you deploy your Strapi application to Heroku.