Step 1- Create a directory :

mkdir new_project

Step 2- Move to new directory then generate express app and install dependencies :

cd new_project
npx express-generator
npm install

Step 3- Install Sequelize, mysql2, passport and bcrypt : npm i sequelize mysql2 passport bcrypt

Step 4- Next, let’s install Postgres and the Sequelize CLI :

npm init -y
npm install sequelize pg
npm install — save-dev sequelize-cli

npm install sequelize pg
npm install — save-dev sequelize-cli

Step 5- Next, let’s initialize a Sequelize project : npx sequelize-cli init

Step 6- Create a database using the Sequelize CLI : npx sequelize-cli db:create

Step 7- Next we open open our database in XAMPP

Step 8- Next we will create a User model from the command line:

npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string,password:string

Step 9- Now we’ll execute our migration to create the Users table in our database:

npx sequelize-cli db:migrate

Step 10- Now let’s create a seed file:

npx sequelize-cli seed:generate --name user

Step 11- Create a controller to contain the router logic in a controller folder:

const connection = require('../models');const bcrypt = require('bcrypt');const jwt =require('jsonwebtoken');const passport = require('passport');const register = async function(req, res){const saltRounds = 10;const salt = bcrypt.genSaltSync(saltRounds);const hash = bcrypt.hashSync(req.body.password, salt);const data = req.body;data.password = hash;await connection.User.create(data);res.json('registration successful');}const login = async function(req, res){const email =;const password = req.body.password;const user = await connection.User.findOne({where:{email : email},});if(!user){return res.json('not user')}const checkPassword = bcrypt.compareSync(password,user.password);if (!checkPassword){return res.json('Password incorrect')}else{const payLoad = {id :,}const token = jwt.sign(payLoad, 'myVerySecret');res.json({'token' : token,'msg' : 'login successful','user' : user,'status' : 200});}}const getUser = async (req, res) => {const data = await connection.User.findOne( {where:{id :}});res.json(data);}module.exports = {register,login,getUser}

Step 12- Create a route:

var express = require('express');const passport = require('passport');var router = express.Router();var userController = require('../controllers/userController');/* GET users listing. */'/register', userController.register);'/login', userController.login);router.get('/', passport.authenticate('jwt',{session:false}), userController.getUser);module.exports = router;

Step 13- Add this to app.js file:

const passport = require('passport');require('./config/passport')(passport);