- cd into clone && run npm install.
- Create a local db.
- Change knexfile.js to reflect your local db name.
- Create a heroku app && postgresql addon.
- put your heroku-postgresql url in the .env_example and rename file right away to .env.
- Run knex commands to make migrations && seeds.
- Migrate latest!
- Don't forget to migrate to heroku.
- Enjoy!
express --hbs name_of_app
creates new express app in a directory called name_of_app--hbs
adds handlebars- assumes you have express-generator package installed globally (
npm install -g express-generator
)
cd name_of_app && npm i
npm i
installs all dependencies denoted by package.json
npm i -S pg knex
installs pg & knex, & adds both to the dependencies in package.jsonknex init
creates 'knexfile.js' in root directory- In root directory, add a folder called 'db' & create 'knex.js' inside it
- in index.js file, add
var knex = require('../db/knex');
- refer to 'db/knex.js' in this repo for how to define your environment configurations
- in index.js file, add
git init
initializes git repoecho node_modules > .gitignore
to add node modules to a .gitignore file OR if you have gitignore installed globally, use commandgitignore node
npm i -S dotenv
installs dotenv module & adds to dependencies in package.json, which loads environment variables from a .env file into process.envtouch .env
in root directory to create empty .env file- add 1 key-value pair per line; when assigning multiple values to one key, separate with
:
- this is where we define
DATABASE_URL=yourURL
later - add
require('dotenv').config();
to top of 'knexfile.js' (so that we can access theDATABASE_URL
variable throughprocess.env
when we define our production environment connection). also add it to 'app.js' (if you're adding other variables that your app will refer to, so it will be available to all routes).
- add 1 key-value pair per line; when assigning multiple values to one key, separate with
echo .env >> .gitignore
adds .env file to .gitignore so git doesn't track it- Why? Because we are going to set the
DATABASE_URL
variable equal to our heroku URL, which contains a password that we don't want others to see
- Why? Because we are going to set the
createdb name_of_app
creates psql database locallyheroku apps:create name-of-app
creates a heroku app (Name must start with a letter and can only contain lowercase letters, numbers, and dashes.)heroku addons:create heroku-postgresql --app name_of_app
adds postgresql database to the appheroku config
returns the URL- add URL to .env file
DATABASE_URL=yourURL?ssl=true
- add URL to .env file
- create a repo on github &
git remote add origin ssh_of_repo
to add the remote git add/commit/push
to github- if you want to open a psql shell 🐚 to the heroku database & run sql commands in the terminal:
heroku pg:psql --app name_of_app
knex migrate:make table_name
to create a new migration- this creates a folder called 'migrations' with a new 'timestamp_table_name.js' file
- Each time you change the table you will need to rerun this command & change the contents of the js file
knex migrate:latest
runs knex migration locally (whatever development environment is set to)knex seed:make seed_name
to create a new seed 🌱- this creates a folder called 'seeds' with a new 'timestamp_seed_name.js' file
knex seed:run
to run seed the local database
If deploying to heroku,
knex migrate:latest --env production
runs knex migration locally against heroku database in the cloudknex seed:run --env production
runs knex locally & puts seed data in heroku databasegit push heroku master
to push to heroku 🎉🎈🎊