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.
├── 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
- Real-time communication using Socket.io.
- Minimal server and client setup for learning purposes.
- Fully self-contained for quick setup.
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
-
Open your web browser and navigate to: http://localhost:3000
-
you should see this
-
sudo apt updateinstall nginx
sudo apt install nginxinstall node
sudo apt install nodejsinstall npm
sudo apt install npmuse npm to install yarn globally
sudo npm install -g yarninstall pm2 globally
sudo npm install pm2 -gmake 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 installRun the application using pm2. this app has their entry point on app.js
use pm2 to start the app
pm2 start app.jsyou can list the process using
pm2 lsconfigure nginx (this could be ignored if using AWS)
sudo apt install ufw
sudo ufw allow 'Nginx HTTP'
sudo systemctl start nginxcreate and update the node app site config
sudo nano /etc/nginx/sites-available/nodeapp.comupdate 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 nginxtest for errors
sudo nginx -trestart nginx
sudo systemctl restart nginxthe app should be on the live url now
you can open the app on different browser to test the communication / live chat between two different browsers or two didferent computer
