Skip to content
ENER90Public

About

🚀 Real-time Chat API - Complete chat system with WebSockets, authentication and message management. Node.js + Express + TypeScript + MongoDB + Socket.io

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Chat API

API de chat en tiempo real con WebSockets (Socket.io), salas públicas/privadas y autenticación JWT.

Stack: Node.js · Express · TypeScript · MongoDB · Socket.io · Docker

Portfolio project — REST + WebSockets, membresía de salas y presencia de usuarios.

Highlights

  • Auth JWT (register / login / me)
  • Mensajería en tiempo real (crear, editar, eliminar)
  • Salas públicas y privadas + join/leave
  • Estado de usuario: online / offline / away
  • MongoDB con Docker Compose

Architecture

REST clients + Socket.io clients
        ↓
   Express + Socket.io
        ↓
 Controllers / event handlers
        ↓
   Mongoose (User, Room, Message)
        ↓
      MongoDB

Quick start

git clone https://github.com/ENER90/chat-api.git
cd chat-api
npm install
cp .env.example .env
docker-compose up -d mongodb
npm run dev

Server: http://localhost:3004

REST endpoints

Auth


### Messages

POST /api/messages/:roomId (auth) GET /api/messages/:roomId (auth) PUT /api/messages/:messageId (auth) DELETE /api/messages/:messageId (auth)


## WebSocket events

**Client → Server:** `join_room`, `leave_room`, `send_message`, `edit_message`, `delete_message`

**Server → Client:** `new_message`, `message_edited`, `message_deleted`, `user_joined`, `user_left`, `error`

## Example

```bash
curl -X POST http://localhost:3004/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"john","email":"john@test.com","password":"123456"}'

curl -X POST http://localhost:3004/api/rooms \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"name":"General Chat","description":"Main chat room","type":"public"}'

curl -X POST http://localhost:3004/api/messages/ROOM_ID \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"content":"Hello everyone!"}'

Environment

PORT=3004
MONGODB_URI=mongodb://admin:password123@localhost:27019/chat-db?authSource=admin
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=7d
CORS_ORIGIN=http://localhost:3004

Author

René Del Valle Rodríguez LinkedIn

License

MIT POST /api/auth/register POST /api/auth/login GET /api/auth/me (auth)


### Rooms

POST /api/rooms (auth) GET /api/rooms GET /api/rooms/:id (auth) POST /api/rooms/:id/join (auth) POST /api/rooms/:id/leave (auth)

About

🚀 Real-time Chat API - Complete chat system with WebSockets, authentication and message management. Node.js + Express + TypeScript + MongoDB + Socket.io

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages