This is the backend for a chat application built with Nest.js, MongoDB, and Prisma. It provides robust features for real-time group chatting with Socket.io and web push notifications.
- Group Chatting: Supports both public channels and private groups.
- Real-Time Communication: Utilizes Socket.io for live message updates.
- Push Notifications: Implemented with web push for notifying users even when the app is closed or in kill mode.
- Node.js: JavaScript runtime for server-side code.
- Nest.js: Framework for building efficient, scalable Node.js server-side applications.
- MongoDB: NoSQL database used to store data.
- Prisma: ORM (Object-Relational Mapping) for database access and management.
- Socket.io: Library for real-time communication.
- Web Push: Technology for sending push notifications to users.
- Swagger Documentation: Api Documentation.
-
Clone the repository:
git clone https://github.com/shkwahab/chatappbackendnestjs.git cd chatappbackendnestjs
-
Install the dependency if you dont have pnpm package manage than follow this setup:
npm i -g pnpm pnpm i
Otherwsie:
pnpm i
-
Create an .env file in the root directory with the following content and replace the keys according to your requirements:
DATABASE_URL = "mongodb://localhost:27017/chatapp"
ACCESS_SECRET_KEY = "JDzIBEsLl9PZOdYp4eQa/IPTgwNVfA2ts2+0lw6Whpc="
REFRESH_SECRET_KEY = "pJEZpMM6xdInYhLk28qL5N9Pob37tsdP7ohQQ4qqb5A="
WEB_PUSH_PUBLIC_KEY = "BFhz7f5ZMJes9tsqQhNQ4W8GyGhhoVxigttI5nlk1whWBBDBo5PXSNvPYaxVawRJnUTm9Rmt14Z4FPCigpFSP-0"
WEB_PUSH_PRIVATE_KEY = "3mvz9AabmvZ3xqxcVGq9Y4isavxiUMm5nmzFhVSoBm0"
WEB_PUSH_MAIL = "yourname@emailprovider.com"
APP_ICON = "https://myapp.com/logo.svg"
SITE_URL = "https://myapp.com"
CLOUDINARY_CLOUD_NAME = "<YOUR_CLOUD_NAME>"
CLOUDINARY_API_KEY = "<YOUR_API_KEY>"
CLOUDINARY_API_SECRET = "<YOUR_API_SECRET>"
-
Set up MongoDB replica set (default port is 27017).
-
Start the application:
Dev Environment:
pnpm start:dev
Production Environment:
pnpm start
Run the server visit: localhost:9000/api-docs Here is the Frontend App Github Repo visit: Frontend App
- Subscribe: Adds a new subscriber to the notification system.
- Send Notification: Sends a push notification to all subscribers.
- Public Channels: Channels where anyone can join and chat.
- Private Groups: Groups where only authorized members can join.