Install bcryptjs to get hash of user password bcrypt.hash params: password + salt + callback(return error and hash value)
npm i bcryptjs
bcrypt.genSalt(10, (err, salt) => {bcrypt.hash(request.body.password, salt, (err, hash) => {}}
Install jsonwebtoken to create Bearer token for authenticate middleware
npm i jsonwebtoken
bcrypt.compare(request.body.password, user.password, (err, result) => {})
jwt.sign(userTokenData, secretOrPrivateKey, options, (err, token) => {})
Get NPM package of PostgreSQL
npm i pg
Get NPM package of sequelize and sequelize-cli
npm i sequelize
or
npm i sequelize-cli
Additional params for connecting in config.json
"protocol": "postgres", "dialectOptions": {"ssl": {"require": true, "rejectUnauthorized": false}},"operatorsAliases": 0
Connection string to database
password:
'password string'
connection string:
'connection_string'
Init sequelize cli to create fiels and folders structure
npx sequelize-cli init
Generate data model with Table name and attributes with data types
npx sequelize model:generate --name Post --attributes title:string,categoryId:integer,content:text,imageUrl:string,userId:integer
Create table and attributes in database via models from previous steps
npx sequelize-cli db:migrate
Create seeders
npx sequelize db:seed --seed all or 'filename'