This is the backend server for a real-time chat application, built with Node.js, Express, and MongoDB. It handles user authentication, friend management, group chats, and message exchange.
- User Authentication (Register, Login, Forgot Password, Reset Password, Change Password)
- User Profile Management (Update Name, Profile Photo)
- Friend Management (Send, Accept, Reject, Cancel Friend Requests, Unfriend, Block, Unblock Users)
- Group Chat Management (Create, Add/Remove Members)
- Real-time Messaging (Send, Edit, Delete Messages)
- Real-time Notifications (Typing indicators, friend requests, profile changes, etc.)
To set up the project locally, follow these steps:
-
Clone the repository:
git clone <repository-url> cd messenger/server
-
Install dependencies:
npm install
-
Environment Variables: Create a
.env
file in theserver
directory with the following content:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key EMAIL_USERNAME=your_email@gmail.com EMAIL_PASSWORD=your_email_password EMAIL_FROM=your_email@gmail.com
Replace the placeholder values with your actual MongoDB connection string, a strong JWT secret, and your Gmail credentials for password reset functionality.
-
Run the development server:
npm start
The server will run on
http://localhost:5000
(or the port specified in your environment).
The API endpoints are documented using OpenAPI (Swagger). You can find the full specification in openapi.yaml
in the project root.
Key endpoint categories include:
/api/auth
: User registration, login, and password management./api/users
: User profile management, and friend requests./api/groups
: Group creation and member management./api/messages
: Sending, editing, and deleting messages.
For detailed request/response schemas and authentication requirements, refer to the openapi.yaml
file.
This application uses Socket.io for real-time communication. The following events are supported:
- connection: Authorizes and connects a user to the socket server.
- join: Joins a user to a room with their user ID.
- sendMessage: Sends a message to a recipient or a group.
- typing: Indicates that a user is typing.
- notification: Sends a notification to a user for events like friend requests, profile changes, etc.
- disconnect: Disconnects a user from the socket server.
For more details on the socket events and their payloads, please refer to the openapi.yaml
file.
To run the automated tests for the API, use the following command:
npm test
This will execute all tests located in the test/
directory.