Push the app in personal GitHub account as public repo.
brew install heroku
-
Make sure you are in your fruit-app folder.
-
heroku create <WHAT-YOU-WANT-YOUR-HEROKU-APP-TO-BE-CALLED>
. This may ask you to login to heroku CLI in the browser. Use heroku login credentials. -
Run
git remote -v
. You should now have at leastorigin
andheroku
remote URLs.heroku https://git.heroku.com/fruit-app.git (fetch) heroku https://git.heroku.com/fruit-app.git (push) origin https://github.com/ishaarora01/fruit-app.git (fetch) origin https://github.com/ishaarora01/fruit-app.git (push)
-
Goto your Heroku App Dashboard.
-
Select your fruit-app
-
Click on "Configure Add-ons".
-
Search for Postgres, select "Heroku Postgres"
-
On the next screen choose Settings, then Reveal Config Vars
-
Heroku gives you a
DATABASE_URL
environment variable. This is the URL to your production database. Another way to check the configuration is by runningheroku config --app fruit-app
infruit-app
on the terminal. -
In your app's
config/config.json
file, we want to use the environment to determine the database URI for our application to connect to."production": { "use_env_variable": "DATABASE_URL" }
-
Heroku looks for instruction when starting your app. In this case, that instruction is to run node
server.js
. In package.json under scripts, add the following..."scripts": { + "start": "node server.js" }
-
Next, push the changes to GitHub repo
$ git add . $ git commit -m "heroku updates" $ git push heroku master
-
Next, run migrations using sequelize-cli. If sequelize cli is not part of package.json dependencies, install it locally by running
npm install sequelize-cli
in the fruit-app.heroku run sequelize db:migrate --env production -m --app fruit-app
OR
Log into your app folder on the actual production server:
heroku run bash
C02W61W9HV2L:fruit-app ishaarora$ heroku run bash Running bash on ⬢ fruit-app-1... up, run.2268 (Free) ~ $ sequelize db:migrate Sequelize CLI [Node: 12.18.4, CLI: 6.2.0, ORM: 6.3.5] Loaded configuration file "config/config.json". Using environment "production". == 20200928144505-create-fruit: migrating ======= == 20200928144505-create-fruit: migrated (0.037s) == 20200928185826-create-user: migrating ======= == 20200928185826-create-user: migrated (0.025s) == 20200929174110-add-userId-to-fruits: migrating ======= == 20200929174110-add-userId-to-fruits: migrated (0.012s) == 20200930141139-create-season: migrating ======= == 20200930141139-create-season: migrated (0.020s) == 20200930143047-create-season-fruit: migrating ======= == 20200930143047-create-season-fruit: migrated (0.024s)
ctrl+d
to exit from heroku bash -
Run
heroku open
to open your app in the browser.
-
Goto your Heroku dashboard and click on "Deploy"
-
For Deployment Method select GitHub
-
For Connect to GitHub type or paste the repo you want to connect.
-
Select "Enable Automatic Deploys"
-
Now, whenever you push to your GitHub repo master branch Heroku will deploy a new build.
-
Next time you push a change to GitHub, your Heroku latest activity should show an automatic build: