A Node.js/Express backend API for a hospital management system. This API handles doctors, appointments, and user authentication. It uses MySQL for database storage and includes file upload capabilities.
- User Authentication: Secure JWT-based authentication.
- Doctors Management: Endpoints to manage doctor profiles.
- Patient Management: Endpoints for patients to register, login, and manage profiles.
- Appointments: Schedule and manage patient appointments with role-based access.
- Payments: Integrated Stripe and Razorpay checkout sessions with automated webhook verification.
- File Uploads: Supports uploading files (e.g., doctor images).
- Error Handling: Centralized error handling middleware.
- Node.js & Express.js for the server environment.
- MySQL2 for database connection and queries.
- JWT (jsonwebtoken) for authorization.
- Bcryptjs for password hashing.
- Multer for handling file uploads.
- Jest & Supertest for unit and integration testing.
src/
├── modules/
│ ├── appointment/ # Appointment logic
│ │ ├── appointment.controller.js
│ │ ├── appointment.model.js
│ │ ├── appointment.routes.js
│ │ └── __tests__/
│ ├── auth/ # Authentication logic
│ │ ├── auth.controller.js
│ │ ├── auth.routes.js
│ │ └── __tests__/
│ ├── doctor/ # Doctor logic
│ │ ├── doctor.controller.js
│ │ ├── doctor.model.js
│ │ ├── doctor.routes.js
│ │ └── __tests__/
│ ├── patient/ # Patient logic
│ │ ├── patient.controller.js
│ │ ├── patient.model.js
│ │ ├── patient.routes.js
│ │ └── __tests__/
│ ├── payment/ # Payment logic
│ │ ├── payment.controller.js
│ │ ├── payment.routes.js
│ │ └── __tests__/
│ └── user/ # Core User data
│ ├── user.model.js
│ └── __tests__/
├── config/
├── middleware/
├── utils/
└── app.js
- Node.js
- MySQL Server
-
Install dependencies:
npm install
-
Environment Variables: Check the
.envfile in the root directory to configure database and authentication variables (e.g.,PORT,DB_HOST,DB_USER,DB_PASSWORD,DB_NAME,JWT_SECRET). -
Database Setup: Ensure your MySQL server is running and the database schema is created as per your configuration.
- Development Mode: (uses nodemon to restart on changes)
npm run dev
- Production Mode:
npm start
Run tests using Jest:
npm test- Watch mode:
npm run test:watch - Coverage report:
npm run test:coverage
- Auth:
/api/auth- Register and authenticate users. - Doctors:
/api/doctors- Manage doctor records. - Patients:
/api/patients- Manage patient records. - Appointments:
/api/appointments- Book and manage appointments. - Payments:
/api/payments- Stripe and Razorpay integrations and webhooks. - Health Check:
/and/test-db- Verify server and database connectivity. - Static Uploads:
/uploads- Access uploaded files.