This is a simple project from nestjs. This project is a Web API for chat applications using websocket and rabbitmq. This project is not intended for applications that will be used for production. only used for examples of using nestjs, rabbitmq, and websocket.
Stack | Min. version |
---|---|
NodeJs | 18.0.0 |
MongoDB | 6.0.0 |
RabbitMq | 3.0.0 |
To run this project, you will need to add the following environment variables to your .env file
MONGODB_URI
= your mongodb uri
JWT_SECRET
= random jwt secret
JWT_EXPIRATION
= jwt expiration duration
RABBITMQ_URI
= your rabbitmq uri
# clone repository
https://github.com/muhaliusman/chat-nest.git
# go to the directory
cd chat-nest
# copy .env.example
cp .env.example .env
# adjust existing parameters
vim .env
# install dependency
npm install
# run the project (Development mode)
npm run start:dev
# access it via localhost:3000
# for (Production mode)
npm run build
# run the project
node dist/main.ts
Install with docker compose
# clone repository
https://github.com/muhaliusman/chat-nest.git
# go to the directory
cd chat-nest
# run docker-compose
docker-compose up
This project has implemented unit tests in it. To run it, just run
npm t
GET /users
POST /users
Parameter | Type | Description |
---|---|---|
username |
string |
Required. unique username |
password |
string |
Required. password min 6 |
POST /auth/login
Parameter | Type | Description |
---|---|---|
username |
string |
Required. your username |
password |
string |
Required. your password |
POST /conversations
Parameter | Type | Description |
---|---|---|
userId |
string |
Required. receiver user |
message |
string |
Required. your message |
Headers | value |
---|---|
Authorization |
Required. Bearer ${token from login response} |
ws://localhost:3000
important: Websocket event to listen conversation_${active_user_id}_${sender_message_id}
- create new user via
Store new user endpoint
- create another user
- login via
login endpoint
- first user open postman and connect to websocket (don't forget to attach jwt token into header)
- for event name use this:
conversation_${active_user_id}_${sender_message_id}
- second user send message to first user via Send Message endpoint