Skip to content

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.

Notifications You must be signed in to change notification settings

Devstein1365/hotel-management

Repository files navigation

Hotel Management Backend API

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.

Features

  • 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

Tech Stack

  • Node.js
  • Express.js
  • MongoDB & Mongoose
  • JWT (jsonwebtoken)
  • bcryptjs (password hashing)
  • dotenv (environment variables)
  • cors

Getting Started

Prerequisites

  • Node.js (v18 or higher recommended)
  • MongoDB database (local or Atlas)

Installation

  1. Clone the repository:
    git clone https://github.com/Goldstein1365/hotel-management.git
    cd hotel-management
  2. Install dependencies:
    npm install
  3. Create a .env file in the root directory and add:
    MONGO_URI=your_mongodb_connection_string
    PORT=5000
    JWT_SECRET=your_jwt_secret
    JWT_EXPIRES_IN=7d
  4. Start the server:
    npm run dev

API Endpoints

Auth

  • POST /api/auth/register — Register a new user
  • POST /api/auth/login — Login and receive a JWT

Rooms

  • GET /api/rooms — List all rooms (with filters)
  • GET /api/rooms/:id — Get details of a room
  • POST /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)

Bookings

  • POST /api/bookings — Create a booking (guest only)
  • GET /api/bookings/mine — Get your bookings
  • GET /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 Authorization header: Bearer <token>

Project Structure

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

License

This project is licensed under the ISC License.

Author

Goldstein1365

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published