Skip to content

This project demonstrates real-time communication between a Next.js frontend and a NestJS backend using WebSockets.

Notifications You must be signed in to change notification settings

NicolasMaso/websockets-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WebSocket Demo - Next.js + NestJS

This project demonstrates real-time communication between a Next.js frontend and a NestJS backend using WebSockets.

Project Structure

  • backend/: NestJS server with WebSocket Gateway (Port 3001)
  • frontend/: Next.js application with interface for sending messages (Port 3000)

πŸš€ Quick Start

Option 1: Automated Script

./start.sh

Option 2: Manual

1. Install Dependencies:

# Backend
cd backend
npm install

# Frontend
cd ../frontend
npm install

2. Run Services:

Terminal 1 - Backend:

cd backend
npm run start:dev

Terminal 2 - Frontend:

cd frontend
npm run dev

3. Access the Application

Open http://localhost:3000 in your browser.

Features

  • βœ… Real-time WebSocket connection
  • βœ… Custom message sending
  • βœ… Ping/Pong system
  • βœ… Visual connection status
  • βœ… Message history
  • βœ… Modern interface with Tailwind CSS

WebSocket Events

Frontend β†’ Backend

  • sendMessage: Sends a message to the server
  • ping: Sends a ping to test the connection

Backend β†’ Frontend

  • messageReceived: Server response with the received message
  • pong: Response to client ping

Technologies Used

  • Frontend: Next.js 15, React, TypeScript, Tailwind CSS, Socket.io-client
  • Backend: NestJS, TypeScript, Socket.io, WebSockets

Main File Structure

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

About

This project demonstrates real-time communication between a Next.js frontend and a NestJS backend using WebSockets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published