This is the backend for a doctor application. It is built using Node.js and Express.js and follows a modular structure for scalability and maintainability.
- Express.js: A fast and minimalist web framework for building APIs.
- Environment Configuration: Uses
.envfiles for environment-specific configurations. - Modular Structure: Organized into
routes,middlewares,services,handlers,models, andutilsfor better code management. - Testing: Includes unit tests using Jest with coverage reports.
- Graceful Shutdown: Handles server shutdown gracefully on termination signals.
.
├── **.env** - Environment variables
├── **.env.example** - Example environment variables
├── **.gitignore** - Files and directories to ignore in Git
├── **index.js** - Entry point of the application
├── **jest.config.js** - Jest configuration
├── **package.json** - Project metadata and dependencies
├── **README.md** - Project documentation
├── **coverage/** - Test coverage reports
├── **handlers/** - API request handlers
├── **middlewares/** - Middleware functions
├── **models/** - Data models
├── **routes/** - API routes
├── **services/** - Business logic and data processing
├── **tests/** - Unit tests
└── **utils/** - Utility functions- Clone the repository:
git clone https://github.com/your-username/backend.git cd backend - Install dependencies
npm install
- Create a .env file based on .env.example:
cp .env.example .env
- Set the PORT variable in the .env file.
-
Development : Start the development server with hot-reloading:
npm run dev
-
Production : Start the production server:
npm run dev
-
Prisma:
- Generate Client:
prisma generate
- Run migrations:
npx prisma migrate dev --name init
- Open Prisma Studio:
npx prisma studio
- Generate Client:
- Run unit tests:
npm test - Run tests in watch mode:
npm run test:watch
- Generate a test coverage report:
npm run test:coverage
- Base URL
http://localhost:<PORT>
GET /appointments/: Retrieves all appointments.GET /appointments/:id: Retrieves a specific appointment by its ID.GET /appointments/user/:userId: Retrieves all appointments for a specific user by their user ID.GET /appointments/doctor/:doctorId: Retrieves all appointments for a specific doctor by their doctor ID.POST /appointments/: Creates a new appointment.PUT /appointments/:id: Updates an existing appointment by its ID.DELETE /appointments/:id: Deletes an appointment by its ID.PATCH /appointments/cancel/:id: Cancels an appointment by its ID.
POST /qrCode/generate: Generates a QR code for a given text.POST /qrCode/verify: Verifies a QR code against expected text and confirms the associated appointment.
GET /: Returns a welcome message.
Feel free to add more details or endpoints as your project evolves!### Routes
GET /appointments/: Retrieves all appointments.GET /appointments/:id: Retrieves a specific appointment by its ID.GET /appointments/user/:userId: Retrieves all appointments for a specific user by their user ID.GET /appointments/doctor/:doctorId: Retrieves all appointments for a specific doctor by their doctor ID.POST /appointments/: Creates a new appointment.PUT /appointments/:id: Updates an existing appointment by its ID.DELETE /appointments/:id: Deletes an appointment by its ID.PATCH /appointments/cancel/:id: Cancels an appointment by its ID.
POST /qrCode/generate: Generates a QR code for a given text.POST /qrCode/verify: Verifies a QR code against expected text and confirms the associated appointment.
GET /: Returns a welcome message.
Feel free to add more details or endpoints as your project evolves! ```
- Routes
GET /: Returns a welcome message.