Created following the tutorial provided by The Coding Garden a wonderful teacher/youtuber!
We'll be using:
-
Postgres for our database
-
knex.js for our database migrations, seeds and queries.
-
express.js for our JSON routes
-
Mocha, Chai and SuperTest to test our routes
-
Prerequisites (Mac OS Commands)
- Latest version of Node.js
- brew install node
- Postgres
- brew install postgres
- brew services start postgres
- createdb
- Express Generator
- npm install -g express-generator
- Knex installed globaly
- npm install -g knex
- Latest version of Node.js
-
Create a server folder
- Generate Express App (command express)
- initialize git repo
-
Create database (command createdb)
-
Initialize knex project
- Install knex and pg (npm command)
- Create knexfile.js (knex init then clean up file make sure to be connected to right database)
-
Create projects table migration (knex migrate:make "name of table" knex migrate:latest)
-
Seed projects table with sample data (knex seed:make 01_project knex seed:run)
-
Convert Express App to JSON API
- Remove view rendering
- Remove routes folder
- Remove static serve and public folder
- Update error handler
-
Add api folder and create/mount router
-
Connect to the database
- Create database connection file
- Create a queries file
-
List all records with GET /api/v1/projects
- Create query
- Create route
-
Setup tests
- Install mocha, chai and supertest
- Add a test database connection
- Add npm test script
- Drop/Create database
- Create before
- Run migrations/seeds on test db
-
Make sure the tests are working!
-
List all records with GET /api/v1/projects
- Add test
-
Show one record with GET /api/v1/projects/:id
- Validate id
- Create query
- Create route
- Add test
-
Create a record with POST /api/v1/projects
- Create route
- Validate projects!
- Create query
- Add test
-
Update a record with PUT /api/v1/projects/:id
- Create route
- Validate id
- Validate updates
- Create query
- Add test
-
Delete a record with DELETE /api/v1/projects/:id
- Create route
- Validate id
- Create query
- Add test
Created following the tutorial provided by The Coding Garden a wonderful teacher/youtuber!