Skip to content

Instantly share code, notes, and snippets.

@bayoishola20
Created April 8, 2018 02:18
Show Gist options
  • Save bayoishola20/40a0fb506efefe4a2b7a50df11c8c1fc to your computer and use it in GitHub Desktop.
Save bayoishola20/40a0fb506efefe4a2b7a50df11c8c1fc to your computer and use it in GitHub Desktop.
Deploying node-postgres app on heroku
## Git initialization
`$ git init`
## Heroku create app
`$ heroku create map-app`
## Assigning remote target
`$ heroku git:remote map-app`
## Confirm
`$ git remote -v`
# preferably use the below in package.json for postgres
"dependencies": {
"pg": "^6.3.1"
},
# define Procfile
web: node start.js
# connecting pg in start.js
const pg = require('pg');
let pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: true,
}) #for local, set connectionString to => "postgres://bayoishola20:bayoishola20@localhost/dishApp"
#refer to https://github.com/bayoishola20/dishApp to see full conifg
# create free heroku postgres database
`$ heroku addons:create heroku-postgresql:hobby-dev`
# to use heroku's postgres console in local terminal
`$ heroku pg:psql`
# visit you Config Vars on heroku and copy value of DATABASE_URL. While in console, type
`$ psql <VALUE OF DATABASE_URL>`
# then create table manually
` $CREATE TABLE dishes(
id SERIAL PRIMARY KEY,
name CHAR(255) NOT NULL,
ingredients TEXT NOT NULL,
directions TEXT NOT NULL,
time TEXT NOT NULL
);`
# confirm table creation
`$ \d`
# quit terminal
`$ \q`
# deploy
`$ git add -A`
`$ git commit -am "commit statement"`
`$ git push heroku master`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment