- Set up Application Express & Database
- Initialize Express JS
- mkdir folder-name // make a directory
- cd folder-name // change to dorectory
- git init // git initialize
- npm init -y // npm initialize with yes answer to all question
- npm install express
- npm install nodemon -G // to hot reload with Global
- touch server.js // create a file
- code . // to open VS Code
- npm run dev // run as dev with nodemon
- Set up PostgreSql Database Using Docker and Initialize Sequelize
- sudo docker --version // to check docker
- mkdir folder-database // make a database directory
- sudo docker run -d --name container-name -p 5430:5432 -e POSTGRES_PASSWORD=password -v ${pwd}/database:/var/lib/postgresql/ata postgres:12 // create container, volume & image postgres
- sudo docker ps // to check container in running
- npm i sequelize sequelize-cli pg pg-hstore dotenv --save // sequelize-cli (ORM), pg-hstore (driver), dotenv (parsing env variable)
- create a file .env
- create a file .sequelizerc
- npx sequelize-cli init // inisialize .sequelizerc
- npm sequelize-cli db:create // create db
- Set up Instance User
- npx sequelize-cli model:generate --name User --attributes \ username:string,email:string,passwod:string \ --underscored // generate db with attibutes
- add tableName in user.js
- add constraint Unique attributes in create-user.js
- npx sequelize-cli db:migrate // to migrate db
note: npx sequlize-cli db:migrate:undo // to change data type
- Make Authentication
- Create Route Auth
- make directory routes then create files index.js & auth.js
- make directory controllers then create file auth-controller.js
- create function register
- Create Register
- create file user.js in routes directory
- npm i bcrypt --save // labrary to hashing password
- trial REST API using postman
- Create Error Handler App Express
- make directory helpers and create file api-error.js
- make dorectory middlewares and create file error-handler.js
- Create Login
- create function login in auth-controller.js
- Create Validation Request Body using Joi
- npm install joi
- create file validation-schema.js in helpers directory
- create file validation.js in middlewares directory
- Create Middleware Authentication JWT
- create file auth-jwt.js in helpers directory
- create payload and token in login function
- create file auth.js in middlewares directory
- create function authentication in auth.js
- create file user-controller.js in controllers directory
- create function profile in user-controller.js
- Create Migrations to add Role attribute in User Table
- npx sequelize-cli migration:generate --name add-role-users
- npx sequelize-cli db:migrate
- Create Middelware Authorization
- create function authorization in middlewares/auth.js
- create function list in controllers/user-controller.js