Screen.Recording.2024-04-09.at.2.12.02.AM.mov
This is the server for our chat application. It uses Node.js, Express, and Socket.IO.
- Clone the repository to your local machine.
- Navigate to the server directory.
- Install dependencies with
npm install
. - Start the server with
npm run dev
.
The server listens for WebSocket connections on the /
namespace. It emits a 'message' event every 5 seconds and a 'userMessage' event every 7 seconds. It also listens for a 'userMessage' event from the client.
When a 'userMessage' event is received from the client, the server emits a 'userMessage' event back to the client with the received message as the data.
When a client disconnects, the server logs 'User disconnected'.
We use JSON Web Tokens (jsonwebtoken) to authenticate users and protect API routes.
User passwords are hashed using bcryptjs.
User email and password are validated using @hapi/joi.