Heroku

So far, your projects only run locally on your computer. But in order to let other people use it, we need to run the app on a computer accessible by others. For sure, you can run your app on your own computer and let other people access the app, but this is not ideal because what if you need to turn off the computer? what your computer crashes? what if your computer is not powerful enough?

So, most people these days will a third-party services to host their server. A lot of people use Amazon Web Services (AWS). AWS allows you to spin up a computer (an instance) and configure it however you want. But, what if you don't want to configure it? You just want it to work with minimal efforts.

Introducing Heroku. Heroku is a layer on top of AWS so that it takes no time to get your app hosted online up and running.

To push your code to Heroku, it works the same as pushing code to Github. You have to add the remote link through $ git remote add <url>, where the url is provided by Heroku. And, pushing your code is as easy as $ git push heroku master which means pushing the code in master branch to heroku.

First, navigate to your app cd path/to/app. Assuming that you have Heroku CLI installed, you can run $ heroku create <name-of-your-app>. <name-of-your-app> is option and has to be a single word.

Once you run $ heroku create, the git remote link is automatically established. It will also create a new app project on Heroku.

You can check the git remote link by running $ git remote -v

-v typically means verbose

$ git remote -v
heroku    https://git.heroku.com/xxxxx-xxxx-25998.git (fetch)
heroku    https://git.heroku.com/xxxxx-xxxx-25998.git (push)

You can deploy your app to Heroku by pushing your code (default is master branch) by running $ git push heroku master. Awesome!

If you don't see an error during deployment, you are ready to check the app out. To quickly open your app on Heroku in the browser, you can run $ heroku open.

Remember that your local database is different from the one on Heroku. You are basically starting a brand new database on another computer. That means that the database schema on Heroku is currently empty. So, you have to run the migrations again by doing $ heroku run rails db:migrate. Notice that we have heroku run in front of rails db:migrate? Whenever we want to run something for the Heroku app, we have to specify it by adding heroku run in front of your usual commands.

results matching ""

    No results matching ""