# ๐Ÿš€ 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! ๐Ÿš€