Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn package manager
- Git for cloning the repository
Get started
Clone the repository
Clone the Medical Appointments API repository to your local machine:git clone https://github.com/Goncar29/proyecto.git
cd proyecto
Install dependencies
Install all required Node.js packages: Configure environment variables
Copy the example environment file and configure your settings:Edit the .env file with your database credentials and JWT secret:PORT=3005
NODE_ENV=development
SALT_ROUNDS=11
DATABASE_URL=postgresql://postgres:your_password@localhost:5432/medical_appointments?schema=public
JWT_SECRET=your-super-secret-jwt-key
Never commit your .env file to version control. It contains sensitive credentials.
Set up the database
Run Prisma migrations to create the database schema:Generate the Prisma client:The Prisma client will be generated in the node_modules/@prisma/client directory.
Seed the database (optional)
Populate the database with sample data for testing: Start the server
Launch the API server: You should see:Servidor escuchando en el puerto http://localhost:3005
Make your first API call
Now that your server is running, let’s test it with a complete authentication flow.
Register a new user
Create a patient account:
curl -X POST http://localhost:3005/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securePassword123",
"name": "John Doe",
"role": "PATIENT"
}'
Response:
{
"message": "Usuario registrado con éxito"
}
Login and get your token
Authenticate to receive a JWT token:
curl -X POST http://localhost:3005/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securePassword123"
}'
Response:
{
"message": "Inicio de sesión exitoso",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Access a protected route
Use your token to access authenticated endpoints:
curl -X GET http://localhost:3005/api/auth/protected-route \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
Response:
Esta es una ruta protegida, acceso permitido para el usuario autenticado.
Replace the token in the Authorization header with the actual token you received from the login endpoint.
Next steps
Authentication
Learn about JWT tokens, role-based access, and security best practices
Time Blocks
Understand how doctors create and manage their availability
Appointments
Learn how patients book and manage their appointments
User Roles
Explore role-based access control for admins, doctors, and patients
Explore the API documentation
Once your server is running, you can access the interactive Swagger documentation at:
http://localhost:3005/api-docs
The Swagger UI provides a complete interactive interface to explore and test all API endpoints.