This project demonstrates real-time communication between a Next.js frontend and a NestJS backend using WebSockets.
- backend/: NestJS server with WebSocket Gateway (Port 3001)
- frontend/: Next.js application with interface for sending messages (Port 3000)
./start.sh1. Install Dependencies:
# Backend
cd backend
npm install
# Frontend
cd ../frontend
npm install2. Run Services:
Terminal 1 - Backend:
cd backend
npm run start:devTerminal 2 - Frontend:
cd frontend
npm run devOpen http://localhost:3000 in your browser.
- β Real-time WebSocket connection
- β Custom message sending
- β Ping/Pong system
- β Visual connection status
- β Message history
- β Modern interface with Tailwind CSS
sendMessage: Sends a message to the serverping: Sends a ping to test the connection
messageReceived: Server response with the received messagepong: Response to client ping
- Frontend: Next.js 15, React, TypeScript, Tailwind CSS, Socket.io-client
- Backend: NestJS, TypeScript, Socket.io, WebSockets
backend/
βββ src/
β βββ chat.gateway.ts # WebSocket Gateway
β βββ app.module.ts # Main module
β βββ main.ts # Application bootstrap
frontend/
βββ app/
β βββ page.tsx # Main page with WebSocket interface