A lightweight, real-time chat application built with Node.js and vanilla JavaScript for LAN or WIFI. This project demonstrates the implementation of a simple but functional chat system with features like message persistence, real-time updates, and a clean user interface.
- Real-time message updates
- Message persistence with timestamps
- Clean and responsive user interface
- Error handling and user feedback
- Automatic message polling
- Message logging system
- Cross-Origin Resource Sharing (CORS) support
- Node.js (v12.0.0 or higher)
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/CodeRafay/chat-app_using-NodeJS--over-wifi-or-lan.git cd chat-app_using-NodeJS--over-wifi-or-lan -
Install dependencies:
npm install
-
Start the server:
node server.js
-
Open your browser and navigate to:
http://localhost:3277
The server can be configured using environment variables:
PORT: The port number the server will listen on (default: 3277)HOST: The host address (default: '0.0.0.0')
Example:
PORT=3000 HOST=localhost node server.jsTo use this chat application within a local area network (LAN) or Wi-Fi network, follow these steps:
-
Run the server on one machine (host):
node server.js
By default, the server listens on port
3277. You can change it using:PORT=3277 HOST=0.0.0.0 node server.js
-
Find the IP address of the host machine:
On Windows, run:
ipconfigLook for the IPv4 Address under your active network adapter (e.g.,
192.168.1.10).On Linux/macOS, run:
ifconfig
or
ip a
-
Access the chat room from other devices on the same network:
Open a browser on any other device and enter:
http://<HOST_IP>:3277For example:
http://192.168.1.10:3277All connected users will now be able to send and receive real-time messages across devices on the same network.
- All devices (host and clients) must be connected to the same LAN or Wi-Fi.
- Firewall settings should allow Node.js to accept incoming connections on the specified port (
3277).
real-time-chat/
├── server.js # Main server file
├── index.html # Frontend interface
├── chat-log.txt # Message log file
└── README.md # Project documentation
- HTTP server implementation using Node.js
- Message storage in memory (with logging to file)
- RESTful API endpoints for message handling
- CORS support for cross-origin requests
- Error handling and logging
- Real-time message updates using polling
- Responsive design
- Error handling and user feedback
- Timestamp display for messages
- Auto-scrolling message container
- Input validation and sanitization
- CORS configuration
- Error handling and logging
- No sensitive data storage
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
- Rafay Adeel
If you encounter any issues or have questions, please open an issue in the GitHub repository.