Express Server with SQL on Heroku

Getting started

Initial Setup

  1. Create a new GitHub repo from this template
  2. Clone your repo down, cd into the directory and open vscode
  3. In the terminal, run npm i to install dependencies.
  4. Copy .env-example as .env
  5. Run heroku create
  6. Run npm run setup-heroku to create:
    1. A production heroku SQL database in the cloud to go with your heroku app
    2. A second dev heroku SQL database in the cloud to use when doing dev development
    3. It returns the dev database url for you to use locally
  7. Copy the url from previous step, or run npm run get-dev-db-url to refetch the url

Create data models

There are package.json script for running parts or all of your db setup:

  1. npm run create-tables - create SQL tables
  2. npm run drop-tables - drop SQL tables
  3. npm run recreate-tables - drop and create SQL tables
  4. npm run load-seed-data - load seed data
  5. npm run setup-db - recreate tables and load seed data

Use these scripts while developing your db model. Inspect progress using PGAdmin Tool. Remember, it should be okay to re-run whole process. The purpose of setup-db is to restore your db to a know "setup" state.

Change all the files in the data directory to match the data model of your app: 1. /data/create-tables.js - SQL to create needed tables 1. /data/drop-tables.js - SQL to drop all tables 1. Seed data file - data to load into the db as starter or "seed" data 1. /data/load-seed-data.js - SQL to insert each item from the seed data array

Running the server

  1. Run npm run start:watch to start the dev server in watch mode

E2E Testing and Adding Routes

  • /__tests__/app.test.js contains testing file for routes. It has before code to run your db setup and after code to close the db connection
  • Use npm run test:watch to start tests in watch mode
  • Routes go in app.js (not server.js)