Skip to content

Created an app in Node.js that uses socket.io to communicate with the user, and the user also needs to perform the login, where login functionality is implemented using the passport strategy.

Notifications You must be signed in to change notification settings

rajgohil07/chat-application-socket.io-sequelize-passport-login-nodejs

Repository files navigation

chat-application-with-socket.io-sequelize-passport-login-nodejs

Tech=>Node.js
Database=>MySql
ORM =>Sequelize
Database_backup_file_name=>db_backup_chat_app.sql
Front_end=>src/view

Additional infomation

Creation of chat application applying socket.io including private chat and broadcast which is administered by passport login moreover Sequelize ORM along with migration integration beside MySql database with proper MVC structure in nodejs.

More info:

link of socket.io : https://socket.io/get-started/private-messaging-part-1/
link of migrations : https://sequelize.org/master/manual/migrations.html

key features

  • login system with passport to store user info in session
  • user can share both private and broadcast message
  • store every message in db with the help of sequilize
  • retrive chat data from db and display it
  • chat stays as it even on page refresh because of sessionStorage
  • list of available users and also remove the user from list if user disconnects
  • proper comments for understandings

Reuired modules

bcrypt @5.0.1
connect-flash @0.1.1
dotenv @10.0.0
ejs @3.1.6
express @4.17.1
express-session @1.17.2
mysql2 @2.2.5
passport @0.4.1
passport-local @1.0.0
sequelize @6.6.2
socket.io @4.1.2

Installing the Sequelize CLI

To install the Sequelize CLI:
npm install sequelize-cli

How to init Migration

To create an empty project you will need to execute init command
npx sequelize-cli init

Creating the first Migration Model

To create a model named User
npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string

To Run Migrations

type the following command to run to migration
npx sequelize-cli db:migrate

To Undo Migrations

You can revert to old state by just running a command.
npx sequelize-cli db:migrate:undo:all

Creating the first Seed

create a seed file which will add a demo user to our User table.
npx sequelize-cli seed:generate --name demo-user

To Run the Seeds

To insert demo user inserted into User table type the following command.
npx sequelize-cli db:seed:all

To Undo Seeds

All the Seeders can be undone if they are using any storage.
npx sequelize-cli db:seed:undo:all

How to Start

Open the directory and install all the required modules by typing the following command
npm i

to create migration with database also insert data as seeds type following command
npm run migrate

After module installation just simply typewrite the following code to start the node server
npm start

to empty the all table data type the following command
npm run clear_data

to remove all tables type the following command
npm run clear_table

How to run in browser

Paste this in browser:-http://127.0.0.1:8081/

About

Created an app in Node.js that uses socket.io to communicate with the user, and the user also needs to perform the login, where login functionality is implemented using the passport strategy.

Topics

Resources

Stars

Watchers

Forks