This tutorial shows you how to setup and connect to Postgres database hosted on Heroku.
Want to know more?
You can check out this detailed instruction on how to set up the database with Heroku.
In this section, you will setup a new Heroku app. In the next step, you will add a database to this app. If you want to use an existing app you can skip to the next section.
- Create a new Heroku account or sign in into an existing account.
- Go to your apps dashboard: https://dashboard.heroku.com/apps.
- To create a new app, click New > Create new app (right-hand side).
- On the next page, enter the app name and click the Create App button.
Now that you have created a Heroku app, the new step is to add a database to this app.
- Inside the newly created app, switch to the Resources tab.
- Under Add-ons, search for Heroku Postgres and then select from the suggested list.
- In the popup shown, select free Hobby Dev - Free plan, click Provision.
- Click on the just added database (Heroku Postgres :: Database).
- Scroll towards the bottom of the page and click on the View Credentials button. You will see the database credentials you will need to use when connecting to this database from API Express.
Now that the database is created you need to create at least one table. You can use any database client of your choice.
We have used pgAdmin database client. Connect to the database using your credentials and the following connection properties:
Then run the following SQL script to create a new table:
CREATE TABLE label ( id int PRIMARY KEY NOT NULL, name varchar(45) )
You are free to use other tools for managing the database data.
Please check out the section here that describes how to fill the database with data by using TablePlus.
That's all for setting up the database.
In this section, you will create a connection to this database from API Express.
- Go to the API Express page.
- Click the Create new DB connection button.
- Enter a connection name and click Create:
- Setup the connection using your Heroku database credentials:
- Test the connection and then click Save:
Updated 4 months ago