This repository contains the backend code for a real-time chat application. It’s built using Express.js, TypeScript, integrates with MongoDB for data storage and AWS for files storage. Users can send and receive messages in real time.
Before you begin, ensure you have the following installed:
- Node.js: Make sure you have Node.js (version 20 or higher) installed on your system.
- npm: The Node.js package manager is required for installing dependencies.
- MongoDB: Set up a MongoDB database (either locally or using a cloud service like MongoDB Atlas).
- Clone the Repository
git clone https://github.com/riyoneri/chat-app-backend.git
- Change working director
cd chat-app-backend
- Install dependencies
npm install
- Environment Variables: Create a .env file in the root directory with the following variables:
# AWS
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_REGION=your-region
AWS_BUCKET_NAME=your-bucket-name
AWS_DISTRIBUTION_DOMAIN_NAME=your-distribution-domain-name
# MONGO DB
MONGODB_URL= your-production-mongodb-url
MONGODB_URL_LOCAL=your-development-mongodb-url
# RESEND
RESEND_API_KEY=your-resend-api-key
# JWT
JWT_SECRET_KEY=your-jwt-secret-key
Note
Amazon S3 (AWS): Amazon S3, provided by AWS, is a scalable and reliable cloud-based storage service. It’s ideal for storing user profile pictures and chat attachments in your app.
Note
MongoDB: MongoDB, a flexible NoSQL database, stores data in JSON-like documents. It’s perfect for chat apps due to its adaptability and powerful querying capabilities.
Note
Resend: Resend simplifies transactional email delivery, ensuring messages avoid spam folders. It supports various programming languages and frameworks, making it developer-friendly.
Note
JSON Web Tokens (JWT): JWTs (JSON Web Tokens) securely transmit information between parties and are commonly used for authentication and data encryption in chat apps.
- Run the server
npm run dev
Note
The server will run on port 3000
by default. You can change this in the app.ts file.
We use Socket.io for real-time communication. When a user sends a message, it’s saved to MongoDB and broadcasted to all connected clients.
Feel free to contribute by opening issues or submitting pull requests. Let’s make this chat app even better!
This project is licensed under the MIT License - see the LICENSE file for details.