Coder Social home page Coder Social logo

express-plus-sql's Introduction

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 local development
    3. It returns the DEV_DATABASE_URL
  7. Copy the DEV_DATABASE_URL from previous step, or run npm run get-dev-db-url to refetch the url

ACP and Branch

  1. ACP your main branch
  2. Work on a new branch: git checkout -b dev (or feature-name or day-02, etc.)

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
  2. /data/drop-tables.js - SQL to drop all tables
  3. Seed data file - data to load into the db as starter or "seed" data
  4. /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)

express-plus-sql's People

Contributors

nickdayfsd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.