This is a simple Node.js Express API for managing hotel rooms.
Click to run the live link on browser
- Node.js
- MongoDB
-
Clone the repository: repo link...;
-
Install dependencies: npm install
-
Set up MongoDB:
- Install MongoDB locally or use a cloud-based MongoDB service.
- Update the MongoDB connection string in
app.js
file to point to your MongoDB instance.
Start the server:
- npm start server.js
By default, the server runs on port 3000. You can change the port by setting the PORT
environment variable.
Create a new room. Request body format:
{
"name": "Room Name",
"roomType": "roomTypeId",
"price": 100
}
GET /api/v1/rooms
Fetch all rooms with optional filters.
Query parameters:
search: Search by room name (case-insensitive)
roomType: Filter by room type ID
minPrice: Filter by minimum price
maxPrice: Filter by maximum price
PATCH /api/v1/rooms/:roomId
Edit a room by its ID.
Request body can include any of the following fields:
name: New room name
roomType: New room type ID
price: New room price
DELETE /api/v1/rooms/:roomId
Delete a room by its ID.
GET /api/v1/rooms/:roomId
Fetch a room by its ID.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.