This repository contains the backend code for a project written in NestJS. The backend is deployed to Amazon EC2 and uses Amazon RDS for the database.
The website is a platform for doctors worldwide to register, provide online consultations, and efficiently manage their schedules. Doctors can easily view their appointments in user-friendly calendars, update their profiles, and set their preferred working hours. To ensure punctuality, doctors receive a notification 5 minutes prior to each scheduled Zoom meeting. The platform facilitates seamless communication between doctors and patients through Zoom calls and an online chat feature. It offers a secure and convenient way for patients to schedule appointments, share medical records, and receive personalized care from a diverse range of doctors. By leveraging technology, the website aims to enhance accessibility to healthcare and empower doctors with greater control over their practice.
Before running the backend locally or deploying it to a server, ensure that you have the following prerequisites installed:
- Node.js (version 18.16.0 or higher)
- Nest CLI (version 9.4.2 or higher)
- Amazon Web Services (AWS) Account
-
Clone this repository:
git clone https://github.com/ZenBit-Tech/WebWizards_be.git
-
Install the dependencies:
cd backend npm install
Before running or deploying the backend, you need to configure some settings.
-
Create a
.env
file in the root directory of the project and add the following environment variables:# Database Configuration DB_HOST=your-database-host DB_PORT=your-database-port DB_USERNAME=your-database-username DB_PASSWORD=your-database-password DB_NAME=your-database-name # SMTP Configuration SMTP_HOST=your-smtp-host SMTP_PORT=your-smtp-port SMTP_USER=your-smtp-username SMTP_PASSWORD=your-smtp-password # API URLs API_URL=your-api-url CLIENT_URL=your-client-url # JWT Configuration PRIVATE_KEY=your-private-key ACCESS_TOKEN_MAX_AGE=your-access-token-max-age # Google Authentication Configuration GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_SECRET=your-google-secret GOOGLE_REDIRECT_URL=your-google-redirect-url # Access Token Configuration ACCESS_TOKEN_DOMAIN=your-access-token-domain # Other Configuration # Add any other required configuration variables here
-
Replace the placeholders in the
.env
file with your actual values.
To run the backend locally, follow these steps:
-
Start the server:
npm run start:dev
The backend server should now be running on
http://localhost:5001
. -
Use a tool like Postman to test the API endpoints.
To deploy the backend to Amazon EC2 using PM2 and a start script, follow these steps:
-
Set up an EC2 instance with your preferred operating system.
-
Install Node.js on the EC2 instance.
-
Clone the repository onto the EC2 instance.
-
Install the dependencies:
cd backend npm install
-
Build the project:
npm run build
This will create a
dist
folder containing the compiled JavaScript files. -
Create a start script file named
start.sh
in the root directory of the project with the following contents:#!/bin/bash npm run start:prod
-
Make the
start.sh
file executable:chmod +x start.sh
-
Configure the environment variables either by setting them in the environment or by modifying the
.env
file. -
Start the backend using PM2:
pm2 start start.sh
The backend should now be running using PM2.
-
Optionally, you can set up PM2 to automatically start the backend on system boot:
pm2 startup pm2 save
This will generate a command that you need to run. Execute the generated command to set up the startup script.
-
Access your backend API using the appropriate URL or IP address of your EC2 instance.
The backend uses Amazon RDS for the database. To set up the database:
-
Log in to your AWS Management Console.
-
Navigate to the Amazon RDS service.
-
Create a new database instance with MySQL.
-
Configure the database credentials and connection details in the
.env
file or set them as environment variables on your EC2 instance.
The backend API is documented using Swagger. You can explore and interact with the API using the Swagger UI.
To access the Swagger documentation, visit Swagger UI or use the following endpoints: