/backend

Homie is an online rental accommodation platform for young professionals and international students who came to Egypt looking for apartment. We allow users to rent a unit as agents and they are also allowed to rent their units as landlords. A unit can be a whole apartment or just a room and you can filter the units to match what you want in a very specific way.

Primary LanguageJavaScript

Homie - NodeJS Backend

Node.js backend for HOMIE: an online rental accommodation platform for young professionals and international students who came to Egypt looking for apartment. We allow users to rent a unit as agents and they are also allowed to rent their units as landlords. A unit can be a whole apartment or just a room and you can filter the units to match what you want in a very specific way.
This repository is a part of our ITI graduation project. We are interns in the MEARN track and our project is built using Angular, MongoDB, Express and NodeJS. You can find all project repos here.

Prerequisites

  • node v12 or higher.
  • npm v6 or higher.
  • MongoDB v6 or higher.

Instructions

Cloning and installing dependencies

Clone the project

  git clone https://github.com/homie-iti/backend

Go to the project directory

  cd backend

Install dependencies

  npm install

Preparing Environment

To run this project, you will need to follow two steps:

  1. create an empty folder in your root and name it db, it will contain all your database files while working locally.
  2. create .env file in your root and use the .env.example file as a reference for you environment variables, add their values as follows:
    PORT: add your preferred app port
    DB_HOST: add your local db host (default 8080)
    DB_PORT: add your local db port (default 'localhost')
    DB_NAME: add your local db name (default 'HomieDB')
    TEST_DB_NAME: add your local test db name (default 'TEST_DB_NAME="HomieTestDB" ')
    JWT_SECRET: add secret key to be used while creating jwt tokens
    SALT_ROUNDS: add number of salt rounds to be used while creating bcrypt hashes (default 10)
    PEXELS_KEY: create an account on pexels.com and add you api key
    UNSPLASH_KEY: create an account on unsplash.com and add you access key
    ATLAS_DB_HOST: add your cloud db host
    ATLAS_DB_USER: add your cloud db access username
    ATLAS_DB_PASSWORD: add your cloud db access password
    ORG_EMAIL: add your organization email
    ORG_EMAIL_PASSWORD: add your organization email password

App Scripts

  1. running the app in the prod mode
  npm start
  1. running the app in the dev mode
  npm run start:dev
  1. running the local app db
  npm run start:db
  1. running the local app db
  npm run start:db
  1. adding data to the local db for testing purposes
  npm run seed-db:local
  1. adding data to the cloud db for testing purposes
  npm run seed-db:atlas
  1. testing the app using the local test db
  npm run test:local
  1. testing the app using the cloud test db
  npm run test:atlas
  1. formatting the code using prettier
  npm run format
  1. fixing linting issues using eslint
  npm run lint:fix
  1. removing old build files (choose cmd or shell based on the machine)
  npm run clean:cmd
  npm run clean:bash
  1. creating new build of the app (choose cmd or shell based on the machine)
  npm run build:cmd
  npm run build:bash

API Schema

We used Swagger to show the full behavior of our api so you can find the full API endpoints in the docs https://homie-iti.herokuapp.com/homie-docs.

Get all elements in a resource

  GET https://homie-iti.herokuapp.com/${resource-name}
Parameter Type Description
resource-name string Required. Resource you want to consume (units, cities, users, reviews...).

Get one item in the resource using its ID

  GET https://homie-iti.herokuapp.com/${resource-name}/${id}
Parameter Type Description
resource-name string Required. Resource you want to consume (units, cities, users, reviews...).
id string Required. Id of item to fetch

Add new element to the resource

  POST https://homie-iti.herokuapp.com/${resource-name}
Parameter Type Description
resource-name string Required. Resource you want to consume (units, cities, users, reviews...).

Update one item in the resource using its ID

  GET https://homie-iti.herokuapp.com/${resource-name}/${id}
Parameter Type Description
resource-name string Required. Resource you want to consume (units, cities, users, reviews...).
id string Required. Id of item to fetch

Delete one item in the resource using its ID

  DELETE https://homie-iti.herokuapp.com/${resource-name}/${id}
Parameter Type Description
resource-name string Required. Resource you want to consume (units, cities, users, reviews...).
id string Required. Id of item to fetch

Pipeline

CircleCI pipeline is triggered when a new commit is pushed to "main" branch

The pipeline has 3 jobs to build, test and deploy the app.

  1. build job starts by installing Node then it cleans the older build files and create a new build
  • circleci/node@5.0.0
  • npm run clean:bash
  • npm run build:bash
  1. test job starts by installing Node and the needed dependencies then it runs the written tests
  • circleci/node@5.0.0
  • npm i
  • npm run test:atlas
  1. And Finally the deploy job deploys the app by uploading files to our heroku branch using the HEROKU_APP_NAME and HEROKU_API_KEY specified in circleci environment variables.
  • circleci/heroku@1.2.6
  • git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git

Authors