This is the backend for CommuneX, a real-time chat application built using Node.js, Express, MongoDB, and Socket.IO.
- User Authentication: Secure login, signup, and logout using JWT and bcrypt.
- Socket.IO Integration: Real-time message broadcasting.
- RESTful API: CRUD operations for users, groups, and messages.
- Rate Limiting: Protects against brute-force attacks.
- Cookie-Based Sessions: Secure HTTP-only cookies for authentication.
- Node.js: Server runtime.
- Express.js: Web framework.
- MongoDB (Mongoose): Database for storing chat data.
- Socket.IO: Real-time communication.
- Bcrypt: Password hashing.
- JWT: Token-based authentication.
- Cookie-Parser: Middleware for parsing cookies.
- Express-Rate-Limit: Prevent abuse.
- Helmet: Security headers.
- Cloudinary: Image management. and more.
- Clone the repository:
git clone https://github.com/aajafry/communex_api.git2.Install dependencies:
npm install- Set up environment variables: Create a
.envfile in the root directory:
PORT=3000
NODE_ENV=(set `production` || `development`)
CORS_ORIGIN=http://localhost:5173
DB_ENDPOINT=mongodb://localhost:27017/communex
JWT_SECRET=(your secret key)CLOUDINARY_CLOUD_NAME=(set your cloudinary cloud name)
CLOUDINARY_API_KEY=(set your cloudinary cloud API key)
CLOUDINARY_API_SECRET=(set your cloudinary API secret)- Run the server:
npm run dev- The server will run at:
http://localhost:3000
The backend provides the following RESTful APIs:
| Route | Method | Description |
|---|---|---|
/auth/signup |
POST | User registration |
/auth/login |
POST | User login |
/auth/logout |
POST | User logout |
| Route | Method | Description |
|---|---|---|
/user/me |
GET | Get user details |
/user/users |
GET | Get all users |
/user/update |
PUT | Update user profile |
/user/delete |
DELETE | Delete user profile |
| Route | Method | Description |
|---|---|---|
/group/create |
POST | Create a group |
/group/getUserGroups |
GET | Get all groups for user |
/group/getGroupMessages |
POST | get all messages of group |
| Route | Method | Description |
|---|---|---|
/message/messages |
POST | get all message of user |
| Route | Method | Description |
|---|---|---|
/cloudinary/delete-image |
POST | delete image from cloudinary |
The CommuneX Frontend repository can be found here. To run the project end-to-end:
- Clone and set up the frontend repository.
- Ensure the backend server is running.
- Update the backend URL in the frontend .env file.
- Start both servers (frontend and backend) to test the integration.