4Geeks Coding Boilerplates for Junior Developers
Deploy to Heroku
Deploy to Heroku
Deploy to Heroku, it takes 7 minutes.
This template is 100% compatible with Heroku, just make sure to understand and execute the following steps.
Create an account on heroku.com, do not create a project, you will do that later, all you need is email and password set.
Install Heroku (if you don't have it yet)
$ npm i heroku -g
- Login to Heroku on the command line (if you have not already)
$ heroku login -i
- Create an application (if you don't have it already)
$ heroku create <your_application_name>
- Install buildpack-registry and buildpacks
$ heroku plugins:install buildpack-registry$ heroku plugins:install buildpacks
- Add Python and also node.js capabilities to Heroku to be able to use npm on production
$ heroku buildpacks:add --index 1 heroku/python$ heroku buildpacks:add --index 2 heroku/nodejs
- Add a new Postgres database to your project
$ heroku addons:create heroku-postgresql:hobby-dev# this command will also automatically add a DATABASE_URL env variable with the Postgres database url
- Other Environment Variables
You cannot create a .env
file on Heroku, instead you need to manually add all the variables using the command line or under your Heroku dashboard project settings.
Open your .env
file and copy and paste each variable (FLASK_APP, FLASK_ENV, etc.) to Heroku. ⚠️ Do not add the DATABASE_URL
variable again, it was already added by Heroku automatically when we added the Postgres add-on.
$ heroku config:set FLASK_APP_KEY="any key works"$ heroku config:set FLASK_APP=src/app.py# ↓ Important: Set to "production"$ heroku config:set FLASK_ENV=production $ heroku config:set BASENAME=/$ heroku config:set BACKEND_URL=
Push your changes!
The last step is to push your code to Heroku with your most recent changes:
$ git add .$ git commit -m 'deploying to heroku'$ git push heroku main
Done!
That is it! If you encounter any issues please refer to the FAQ Heroku file.
Edit this page on GitHub