This is a backend RESTful API for a Hotel Management System, built with Node.js, Express.js, and MongoDB. It provides endpoints for user authentication, room management, and booking management. There is no frontend included in this project.
- User registration and login with JWT authentication
- Role-based access control (admin, guest)
- Room CRUD operations (admin only for create, update, delete)
- Room filtering and search
- Booking creation, viewing, and cancellation
- Prevents double-booking of rooms for overlapping dates
- Node.js
- Express.js
- MongoDB & Mongoose
- JWT (jsonwebtoken)
- bcryptjs (password hashing)
- dotenv (environment variables)
- cors
- Node.js (v18 or higher recommended)
- MongoDB database (local or Atlas)
- Clone the repository:
git clone https://github.com/Goldstein1365/hotel-management.git cd hotel-management - Install dependencies:
npm install
- Create a
.envfile in the root directory and add:MONGO_URI=your_mongodb_connection_string PORT=5000 JWT_SECRET=your_jwt_secret JWT_EXPIRES_IN=7d
- Start the server:
npm run dev
POST /api/auth/register— Register a new userPOST /api/auth/login— Login and receive a JWT
GET /api/rooms— List all rooms (with filters)GET /api/rooms/:id— Get details of a roomPOST /api/rooms— Create a room (admin only)PATCH /api/rooms/:id— Update a room (admin only)DELETE /api/rooms/:id— Delete a room (admin only)
POST /api/bookings— Create a booking (guest only)GET /api/bookings/mine— Get your bookingsGET /api/bookings— Get all bookings (admin only)PATCH /api/bookings/:id/cancel— Cancel a booking (owner or admin)
All protected routes require a JWT token in the
Authorizationheader:Bearer <token>
hotel-management/
│── server.js
│── config/
│ └── db.js
│── models/
│ ├── User.js
│ ├── Room.js
│ └── Booking.js
│── routes/
│ ├── authRoutes.js
│ ├── roomRoutes.js
│ └── bookingRoutes.js
│── controllers/
│ ├── authController.js
│ ├── roomController.js
│ └── bookingController.js
│── middleware/
│ └── auth.js
│── .env
│── .gitignore
│── package.json
This project is licensed under the ISC License.
Goldstein1365