Files
Hotel-Booking/server/QUICK_START.md
Iliyan Angelov 93d4c1df80 update
2025-11-16 15:12:43 +02:00

166 lines
3.1 KiB
Markdown

# 🚀 QUICK START - Server Setup
## Step 1: Copy .env file
```bash
cd d:/hotel-booking/server
cp .env.example .env
```
> The .env file has been pre-created with default configuration
## Step 2: Create Database (if not exists)
```bash
# Open MySQL command line
mysql -u root -p
# Create database
CREATE DATABASE hotel_db;
# Exit
exit;
```
## Step 3: Run Migrations
```bash
cd d:/hotel-booking/server
npm run migrate
```
This command will create the following tables:
- roles
- users
- refresh_tokens
- rooms
- room_types
- bookings
- payments
- services
- service_usages
- promotions
- checkin_checkout
- banners
- password_reset_tokens
- reviews
## Step 4: (Optional) Seed Data
```bash
npm run seed
```
This command will create:
- 3 roles: admin, staff, customer
- Demo users
- Demo rooms & room types
- Demo bookings
## Step 5: Start Server
```bash
npm run dev
```
You will see:
```
✅ Database connection established successfully
📊 Database models synced
🚀 Server running on port 3000
🌐 Environment: development
🔗 API: http://localhost:3000/api
🏥 Health: http://localhost:3000/health
```
## Step 6: Test API
### Health Check
Open browser: http://localhost:3000/health
### Test Login (after seeding data)
```bash
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@hotel.com","password":"Admin123"}'
```
## ⚠️ Troubleshooting
### Error: "Access denied for user 'root'"
**Solution:** Update DB_PASS in `.env` file
```bash
DB_PASS=your_mysql_password
```
### Error: "Unknown database 'hotel_db'"
**Solution:** Create database manually (Step 2)
### Error: "Port 3000 already in use"
**Solution:** Change PORT in `.env`
```bash
PORT=3001
```
### Error: "Cannot find module"
**Solution:** Reinstall dependencies
```bash
npm install
```
## 📝 Next Steps
1. ✅ Server is running
2. ✅ Database is set up
3. ✅ API endpoints are ready
4. 🔜 Test with frontend login form
5. 🔜 Implement remaining APIs
## 🧪 Test với Postman
**Collection:** Hotel Booking API
### 1. Register
```
POST http://localhost:3000/api/auth/register
Body (JSON):
{
"name": "Test User",
"email": "test@example.com",
"password": "Test1234",
"phone": "0123456789"
}
```
### 2. Login
```
POST http://localhost:3000/api/auth/login
Body (JSON):
{
"email": "test@example.com",
"password": "Test1234",
"rememberMe": true
}
```
### 3. Get Profile
```
GET http://localhost:3000/api/auth/profile
Headers:
Authorization: Bearer YOUR_ACCESS_TOKEN
```
## ✅ Checklist
- [ ] MySQL is running
- [ ] .env file has been created and configured correctly
- [ ] Database hotel_db has been created
- [ ] Migrations have run successfully
- [ ] Server is running (port 3000)
- [ ] Health check returns 200 OK
- [ ] Frontend .env has VITE_API_URL=http://localhost:3000
- [ ] Frontend is running (port 5173)
## 🎯 Ready to Test Login!
1. Server: http://localhost:3000 ✅
2. Client: http://localhost:5173 ✅
3. Login page: http://localhost:5173/login ✅
4. API endpoint: http://localhost:3000/api/auth/login ✅
**Everything is ready!** You can now test the login form from the frontend! 🚀