Skip to content

Repository files navigation

Niwas

Niwas is a web application for listing and browsing rental properties. Built with Node.js, Express, MongoDB, and EJS, it demonstrates CRUD operations, RESTful routing, and server-side rendering.


🚀 Features

  • View all property listings
  • Create new listings
  • Edit existing listings
  • Delete listings
  • Leave and manage reviews for listings
  • Responsive UI with Bootstrap 5
  • Data stored in MongoDB
  • Server-side rendering with EJS & ejs-mate
  • RESTful API design
  • Flash messages for user feedback

🛠️ Technologies Used

  • Node.js
  • Express.js
  • MongoDB & Mongoose
  • EJS & ejs-mate
  • Bootstrap 5
  • Joi (validation)

📦 Project Structure

Niwas/
├── .git/
├── app.js
├── cloud-config.js
├── package.json
├── package-lock.json
├── README.md
├── schema.js
├── .env
├── .gitignore
├── controllers/
│   ├── listingControllers.js
│   ├── reviewControllers.js
│   └── userControllers.js
├── init/
│   ├── index.js
│   └── sampleData.js
├── models/
│   ├── listing.js
│   ├── reviews.js
│   └── user.js
├── public/
│   ├── favicon.svg
│   ├── css/
│   │   ├── style.css
│   │   └── rating.css
│   └── js/
│       └── script.js
├── routes/
│   ├── listingRoutes.js
│   ├── reviewRoutes.js
│   └── userRoutes.js
├── utils/
│   ├── ExpressError.js
│   ├── middlewares.js
│   └── wrapAsync.js
├── views/
│   ├── error/
│   │   └── error.ejs
│   ├── includes/
│   │   ├── footer.ejs
│   │   └── navbar.ejs
│   ├── layouts/
│   │   └── boilerplate.ejs
│   ├── listings/
│   │   ├── edit.ejs
│   │   ├── flash.ejs
│   │   ├── index.ejs
│   │   ├── new.ejs
│   │   └── show.ejs
│   └── users/
│       ├── login.ejs
│       └── signup.ejs

⚙️ Environment Variables

Create a .env file in the root directory to store environment variables:

PORT=8080
MONGO_URI=mongodb://127.0.0.1:27017/db_name
SECRET=your_secret_key_for_sessions
CLOUD_NAME=your_mongoDB_cloud_name
CLOUD_API_KEY=your_cloudinary_API_KEY
CLOUD_API_SECRET=your_cloudinary_API_SECRET

⚡ Getting Started

Prerequisites

Installation

  1. Clone the repository:
    git clone git@github.com:developershivam-sudo/GharExpress.git
    cd GharExpress
  2. Install dependencies:
    npm install
  3. Start MongoDB locally (default port 27017).
  4. (Optional) Seed the database with sample data:
    node init/index.js
  5. Start the application:
    node app.js
  6. Visit the app: http://localhost:8080

💡 Usage

  • Home Page: View all listings.
  • Add New Listing: Click "Add New Listing" in the navbar to create a new property.
  • Edit/Delete: On a listing's detail page, use the Edit or Delete buttons.
  • Reviews: Leave reviews for listings and manage them.

📝 API Endpoints

Listings

  • GET /listings — View all listings
  • GET /listings/new — Render form to create a new listing
  • POST /listings/create — Create a new listing
  • GET /listings/:id — View details of a listing
  • GET /listings/:id/edit — Edit a listing
  • PUT /listings/:id — Update a listing
  • DELETE /listings/:id — Delete a listing

Reviews

  • POST /listings/:id/reviews — Add a review to a listing
  • DELETE /listings/:id/reviews/:reviewId — Delete a review

🧪 Validation

  • Server-side validation: Implemented using Joi schemas for listings and reviews.
  • Client-side validation: Bootstrap validation for forms.

📄 License

This project is licensed under the ISC License.


👤 Author

SHIVAM