This project is a backend server built with TypeScript, using Express for the web framework, Socket.IO for real-time communication, MongoDB as the database, and Node.js as the runtime. It also incorporates password hashing for security, CI/CD pipeline for automated testing and deployment, and containerization using Docker and Docker Compose.
- Real-Time Communication with Socket.IO.
- MongoDB for data storage.
- Password Hashing for secure authentication.
- CI/CD for continuous integration and delivery.
- Dockerized application for easy deployment and environment consistency.
Make sure you have the following installed:
- Node.js (v16 or higher)
- MongoDB (locally or via MongoDB Atlas)
- Docker and Docker Compose (if using containerized setup)
-
Clone the repository:
git clone https://github.com/RanaZaeem0/Mern_chatapp cd backend-project
-
Install dependencies:
npm install
-
Configure environment variables:
Copy the
.env.example
to.env
and configure the environment variables, including MongoDB URI and JWT secret.cp .env.example .env
-
Run the server:
For development:
npm run dev
This will start the server with hot-reloading (via
ts-node-dev
).For production:
npm run build npm start
- POST /login: Authenticate users (Password is hashed and stored securely).
- GET /users: Retrieve all users from the database.
- POST /message: Send a real-time message to connected users via Socket.IO.
-
Build the Docker image:
docker build -t backend-project .
-
Run the container:
docker run -p 3000:3000 backend-project
This will start the application inside a Docker container, exposing port 3000
.
-
Start the project with Docker Compose:
Make sure Docker Compose is installed, then run:
docker-compose up
This will automatically build the image and start the containers for both the backend and MongoDB.
-
Stop the containers:
docker-compose down
This project uses a CI/CD pipeline for automated testing and deployment. The pipeline includes:
- GitHub Actions for running tests, linting, and building the application.
- Automated deployment to your server or cloud platform (e.g., AWS, Heroku).
Check the .github/workflows
directory for CI configuration files.
Here is an overview of the project structure: