Doctors.com backend provides API endpoints and functionalities to manage hospital and patient-related operations. This backend supports features like uploading patient reports, submitting reports to specific hospitals, and searching for hospitals from a database.
- User Authentication: Secure authentication using JSON Web Tokens (JWT).
- File Uploads: Upload patient reports using Multer middleware, with optional Cloudinary integration for storing files.
- Hospital Search: Search for hospitals from the database using efficient queries.
- Report Submission: Submit patient reports to a specific hospital.
- Data Security: Passwords are hashed using bcrypt.
- Pagination: Paginate results for hospital listings and search queries to improve performance and user experience.
- MongoDB Pipelines:
- Fetching all hospitals with aggregation pipelines to include relevant data and support filtering/sorting.
- Submitting reports by aggregating and validating hospital and patient data.
- Searching for a specific hospital by its name using optimized text indexes or regex patterns.
-
Clone the repository:
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following environment variables:PORT=8000 MONGODB_URI= CORS_ORIGIN= ACCESS_TOKEN_SECRET= ACCESS_TOKEN_EXPIRY=1d REFRESH_TOKEN_SECRET= REFRESH_TOKEN_EXPIRY=7d CLOUDINARY_CLOUD_NAME= CLOUDINARY_API_KEY= CLOUDINARY_API_SECRET=
-
Start the server:
npm run dev
| Dependency | Purpose |
|---|---|
| bcrypt | Hashing passwords for secure authentication. |
| cloudinary | Storing and managing uploaded reports. |
| cookie-parser | Parsing cookies for request handling. |
| cors | Enabling Cross-Origin Resource Sharing (CORS). |
| dotenv | Loading environment variables from .env. |
| express | Backend framework for handling requests. |
| jsonwebtoken | Creating and verifying JWTs for authentication. |
| mongoose | MongoDB ODM for data modeling and queries. |
| mongoose-aggregate-paginate-v2 | Paginating query results in MongoDB. |
| multer | Middleware for file uploads. |
| npm | Node.js package manager. |
- POST
/api/v1/users/register- Register a new user. - POST
api/v1/users/login- Authenticate and log in a user.
- GET
api/v1/hospitals/all- Fetch a list of hospitals. - GET
api/v1/hospitals/{hospitalID}- Get details of a specific hospital.
- Multer is used to handle file uploads.
- Cloudinary is integrated for storing uploaded files securely in the cloud.
The backend uses MongoDB as the database, and Mongoose is used as the ODM for defining schemas and querying the database.
const patientSchema = new Schema(
{fullname: {
type: String,
required: true,
trim: true,
index: true,},
email: {type: String,
required: true,
unique: true,
lowercase: true,
trim: true },
password: {type: String,required: [true, "Password is required"],},
phonenumber: {type: String,trim: true,},
profilephoto: {type: String, //cloudinary url},
reports: {type: [String], //cloudinary url},
hiddenreports: {type: [String], //cloudinary url},
hospitals: [{ type: Schema.Types.ObjectId,ref: "Hospital",},],
dob: { type: String,},
bloodgroup: { type: String, },
gender: {type: String,},
refreshToken: { type: String}},
{timestamps: true,});- Password Hashing: User passwords are securely hashed using bcrypt.
- JWT: Tokens are used for secure authentication and session management.
Contributions are welcome! Please fork the repository and create a pull request.
Created with ❤️ by Aniket