Staywise is a backend server for an Airbnb-like platform, built with Node.js, Express, and MongoDB. It provides RESTful APIs for user authentication, property listings, bookings, reviews, and user management.
- User authentication (signup, login, JWT-based auth)
- CRUD operations for property listings
- Booking system for guests and hosts
- Review system for listings
- User profile management and favorites
- File uploads (Cloudinary integration)
- Clone the repository
- Install dependencies:
npm install
- Set up environment variables:
- Copy
.env.exampleto.envand fill in your values (see below).
- Copy
- Start the server:
npm run dev
TOKEN_SECRET- Secret for JWTMONGO_URI- MongoDB connection stringPORT- Server port (default: 3005)CLOUDINARY_CLOUD_NAME,CLOUDINARY_API_KEY,CLOUDINARY_API_SECRET- Cloudinary credentials
config/ # Database connection
error-handling/ # Error handling middleware
middleware/ # Custom Express middlewares
models/ # Mongoose models
routes/ # Express route handlers
uploads/ # File uploads (local)
utils/ # Utility functions (e.g., cascade delete)
validators/ # Request validation logic
server.js # Entry point
name,email,password,avatarUrl,favorites,phone,address
hostId,title,description,pricePerNight,address,amenities,photos,maxGuests,bedrooms,bathrooms
listingId,guestId,checkIn,checkOut,totalPrice,status
listingId,bookingId,authorId,rating,comment
line1,line2,city,state,country,postalCode,location
POST /signup- Register a new userPOST /login- Login and receive JWTGET /verify- Verify JWT and get user info
GET /- Get current user profilePUT /- Update user profileDELETE /- Delete user and cascade delete dataGET /favorites- Get user's favorite listingsPOST /favorites/:listingid- Add listing to favoritesDELETE /favorites/:listingid- Remove listing from favorites
GET /- Get listings (with filters)POST /by-ids- Get listings by IDsGET /host- Get listings owned by current hostGET /:listingid- Get listing detailsGET /:listingid/bookings- Get bookings for a listingPOST /- Create a new listing (host only)PUT /:listingid- Update a listing (host only)DELETE /:listingid- Delete a listing (host only, cascade delete)
GET /- Get bookings for current userPOST /- Create a new bookingPUT /:bookingid/cancel- Cancel a booking (guest)GET /host- Get bookings for host's listingsPUT /:bookingid/cancel/host- Cancel a booking (host)
GET /booking/:bookingId- Get review for a bookingPOST /- Create a reviewPUT /:reviewid- Update a reviewDELETE /:reviewid- Delete a reviewGET /listings/:listingId- Get reviews for a listing
- Cascade Delete:
- Deleting a user or listing will also delete related bookings, reviews, and remove from favorites.
MIT