A real-time chat application built with Node.js, Express.js, and WebSockets.
- Real-time messaging using WebSockets
- Stores chat messages and sends them to new clients on connection
- Uses EJS for templating
- Serves static assets
- CORS enabled for cross-origin requests
Ensure you have Node.js installed on your system.
- Clone the repository:
git clone https://github.com/GHDBASHEN/node-websocket.git cd node-websocket - Install dependencies:
npm install
- Start the server:
The Express server will run on
npm start
http://localhost:3000and the WebSocket server onws://localhost:3001.
You can customize the server settings using environment variables:
| Variable | Description | Default |
|---|---|---|
PORT |
HTTP server port | 3000 |
WSPORT |
WebSocket server port | 3001 |
NAMELEN |
Maximum length for usernames | 15 |
MSGLEN |
Maximum length for chat messages | 200 |
node-websocket-chat/
├── views/ # EJS templates
├── static/ # Static assets (CSS, JS, images)
├── index.js # Main Express and WebSocket server
├── package.json # Project dependencies and scripts
└── README.md # Project documentation
- Open
http://localhost:3000in your browser. - Send and receive messages in real-time.
This project is licensed under the MIT License.
