- A Heroku account, with:
- An active subscription to the Eco Dynos Plan
- A credit card on file so that you can pay for the Heroku Postgres Add-On.
- An install of the Heroku CLI. (CLI: Command Line Interface)
npm install -g heroku
- An install of PostgreSQL's CLI Tools.
- The ability to successfully authenticate with Heroku by typing
heroku login
in your Terminal.- This will prompt you to press a key and you'll be directed to log in through the Heroku web app.
- The project you'd like to deploy must be a
git
repository. (Derp.)
Before you deploy, make sure your server PORT
is configured correctly as:
const PORT = process.env.PORT || 5001;
And make sure your **modules/pool.js**
has some conditional code using process.env.DATABASE_URL
like:
if (process.env.DATABASE_URL) {
config = {
// We use the DATABASE_URL from Heroku to connect to our DB
connectionString: process.env.DATABASE_URL,
// Heroku also requires this special `ssl` config
ssl: { rejectUnauthorized: false },
};
} else {
// If we're not on heroku, configure PG to use our local database
config = {
host: 'localhost',
port: 5432,
database: 'prime_app', // CHANGE THIS LINE to match your local database name!
};
}
Run the following terminal commands from within your project folder's root directory.
heroku create
- Log in in if prompted.
- This will instantiate a Heroku app.
git remote -v
to ensure it added successfullyheroku addons:create heroku-postgresql:essential-0
- Note:
essential-0
can be replaced with whichever plan you prefer.
- Note:
Run the following commands from within your project folder's root directory.
heroku pg:push your_database DATABASE_URL
- Replace
your_database
with the actual name of your local PostgreSQL database. - This command effectively pushes up a copy of that database to Heroku.
- If this doesn't work, ensure that you've installed PostgreSQL's CLI Tools and restarted your terminal!
- Replace
git push heroku main
- This will push your project repository up to Heroku.
- That's deployment. If everything worked,
heroku open
should successfully open your app in the browser.
heroku logs
- Display the most recent Heroku-hosted server logs.heroku logs --tail
- Display Heroku-hosted server logs as they occur in real time.
heroku config
- Show basic app info.heroku restart
- Sometimes it helps to turn things off an on again. 🙂heroku open
- Opens the website for you project in the browser.
If you would like to view/edit your hosted database, you can actually use Postico!
- From your Heroku Dashboard, click your application.
- Then, click the Resources tab.
- In the Add-ons section, click Heroku Postgres.
- Click the
Settings
tab, then clickView Credentials
- Open Postico, then click
New Favorite
. - In the new Postico favorite, update the following to match Heroku:
Host
Database
User
Port
Password
- Click
Connect
and you should have access to your database directly from Postico!