# 🏨 Node.js Hotel API
A secure **Hotel Management API** built with **Node.js**, **Express.js**, and **MongoDB**.
This API allows users to perform CRUD operations on hotel menus — **create**, **read**, **update**, and **delete** — with **authentication** and **password protection** using **Jwt** and **bcrypt.js**.
---
## 🚀 Features
- 🔐 **User Authentication** using Jwt Auth
- 🔒 **Password Hashing** with bcrypt.js
- 📋 **CRUD Operations** on Menu Items
- 🗂️ **MongoDB Integration** using Mongoose
- ⚙️ **Environment Variables** with dotenv
- 🧠 **Protected Routes** (only authenticated users can access `/menu`)
- 🔄 **RESTful API Design**
---
## 🏗️ Tech Stack
| Technology | Purpose |
|-------------|----------|
| **Node.js** | Server runtime |
| **Express.js** | Web framework |
| **MongoDB + Mongoose** | Database & ODM |
| **Jwt** | Authentication |
| **bcrypt.js** | Password encryption |
| **dotenv** | Environment variables |
| **body-parser** | Parsing request bodies |
| **Lodash** | Utility functions |
| **Nodemon** | Auto server restart during development |
---
## 📁 Project Structure
📦 hotel-api ┣ 📂 auth ┃ ┗ auth.js # Passport configuration (local strategy) ┣ 📂 models ┃ ┗ menuModel.js # MongoDB schema for menu items ┣ 📂 routes ┃ ┗ menuRoutes.js # Routes for menu CRUD operations ┣ 📜 db.js # Database connection setup ┣ 📜 server.js # Entry point of the app ┣ 📜 package.json # Dependencies and scripts ┣ 📜 .gitignore # Ignored files for Git
---
## ⚙️ Installation & Setup
### 1️⃣ Clone the Repository
```bash
git clone https://github.com/<your-username>/hotel-api.git
cd hotel-api
npm installPORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_keynpm startServer will run on:
👉 http://localhost:5000
The app uses Jwt Auth Token to authenticate users.
POST /signup
{
"username": "john_doe",
"password": "mypassword"
}POST /login
{
"username": "john_doe",
"password": "mypassword"
}After login, you will get an authenticated session and can access protected routes.
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /menu |
Get all menus | ✅ Yes |
| POST | /menu |
Add a new menu | ✅ Yes |
| PUT | /menu/:id |
Update a menu | ✅ Yes |
| DELETE | /menu/:id |
Delete a menu | ✅ Yes |
- Passwords are hashed using
bcrypt.jsbefore saving. - Routes are protected using Passport’s
isAuthenticated()middleware. - CSRF protection and validation can be added for extra safety.
# Login
curl -X POST http://localhost:3000/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"1234"}'
# Get Menus (after login)
curl -X GET http://localhost:3000/menu \
-b cookie.txt -c cookie.txtThis project is licensed under the ISC License.
Adityam Kumar 💻Portfolio 💻 Built with ❤️ using Node.js & Express.js