Skip to content

slimprepdevops/basic-group-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js App with Socket.io

This is a simple Node.js application demonstrating real-time communication using Socket.io. It includes both server-side and client-side components for a basic WebSocket-based application.

Project Structure

├── README.md          # Project documentation
├── app.js             # Main application file
├── index.html         # Frontend HTML file
├── package-lock.json  # Automatically generated for dependency management
└── package.json       # Project metadata and dependencies

Features

  • Real-time communication using Socket.io.
  • Minimal server and client setup for learning purposes.
  • Fully self-contained for quick setup.

Setup On Your System (Local)

Follow the steps to setup the application

  • Node.js:

    • Ensure that NodeJS is installed, if it is not:
    • Download and install from Node.js Official Website.
    • Verify the installation by running the commands below:
    node -v
    npm -v

    These should return the node versions installed on your machine

  • Clone or Download the Project

    • Clone the repository using Git:
    git clone <repository-url>
    • Alternatively, download and extract the ZIP file.
  • Install Dependencies

    • Navigate to the project directory using terminal and install the required packages:
    npm install
  • Run the Application

    node app.js

    this should run the ap on *:3000

  • Access the Application

    chat-screen


Setup on EC2 Instance

sudo apt update

install nginx

sudo apt install nginx

install node

sudo apt install nodejs

install npm

sudo apt install npm

use npm to install yarn globally

sudo npm install -g yarn

install pm2 globally

sudo npm install pm2 -g

make a directory and clone repo into directory

mkdir app && cd app && git clone <repositori-url> .

run this inside the app directory to install all required dependencies

npm install

Run the application using pm2. this app has their entry point on app.js

use pm2 to start the app

pm2 start app.js

you can list the process using

pm2 ls

configure nginx (this could be ignored if using AWS)

sudo apt install ufw
sudo ufw allow 'Nginx HTTP'
sudo systemctl start nginx

create and update the node app site config

sudo nano /etc/nginx/sites-available/nodeapp.com

update the details with the below

server { 
	listen   80; 
    server_name <your_ip_or_domain>; 
 
    location / { 
			proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header Host $host; 
            proxy_set_header X-NginX-Proxy true; 
            proxy_pass http://localhost:3000/; 
            proxy_redirect http://localhost:3000/ https://$server_name/; 
    } 
}

notice that the proxy_redirect takes to parameters, one ending with :3000 and the other ending with $server_name, this is one way to setup proxy using nginx. The first parameter is the entry point within the node environment, the second one $server_name redirects any servername request to the defined port or proxy informaion

sudo ln -s /etc/nginx/sites-available/nodeapp.com /etc/nginx/sites-enabled/

disable existing config

sudo rm /etc/nginx/sites-enabled/default
sudo systemctl reload nginx

test for errors

sudo nginx -t

restart nginx

sudo systemctl restart nginx

the app should be on the live url now


Post Test

you can open the app on different browser to test the communication / live chat between two different browsers or two didferent computer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published