Creating the template for a backend
- npm i knex sqlite3 express dotenv bcryptjs jsonwebtoken pg
- npm i -D nodemon supertest jest cross-env
- port information with env variable
- require dotenv config
- server listen
- Express
- Server
- API Requests
- Export Server
- "start":"node index.js"
- "server":"nodemon index.js"
- copy and paste stuff
- npx knex migrate:make users-table
- npx knex seed:make 001-users
- knex
- config -> knexfile
- environment
- export config
- incrementing id
- username unique notNull
- password notNull
- name [optional]
- age integer [optional]
- subscription bool [optional] - default to false
- {id: 1, username: "Devin", password: "Devin", age: 14, subscription: false, name: "Devin"} npx knex seed:run
- Users
- Users Model
- require database from dbConfig
- database helper functions
- Users Router
- Auth Router
- router = express("express").router()
- import bcrypt
- import Users from users-model
- Login post
- Register post with JSONWEBTOKEN
- Import
- Generate Token Function
- ./config/secrets.js file
- exported secret
-
User Profile
- get information
- update information
- Included restricted middleware
-
User has an array of something
- add item to something
- delete item to something
- get somethings
- update somethings
- Change knexfile stuff (import and production object)
- Heroku
- Resources: heroku prostgres add on
- Setting: DB_ENV ==> production
- npx heroku run knex migrate:latest -a
- npx heroku run knex seed:run -a
- Test endpoint in insomonia
- npx knex migrate:latest --env=testing
- npx knex seed:run --env=testing
- Seed Data
- Depoly on Heroku
- Tests
- Implement Cookies for extra security
- Documentation !!!!!