Skip to content
Michał Plebański edited this page May 14, 2021 · 4 revisions

NestJS backend

Install dependencies (instructions are for MacOS)

  1. Install Node.js 12.x and Yarn package manager:

    brew install node@12. yarn
  2. Install redis by following the instructions here.

  3. Install Postgres 12 DB:

    brew install postgresql@12
    

    and create a new database called bloom.

    psql -c 'CREATE DATABASE bloom;`
  4. Clone this repository:

    git clone https://github.com/bloom-housing/bloom.git
    
  5. Install project dependencies

    cd backend/core && yarn install
    

Configure environment

1 . Define environment variables for local based on a provided template:

# backend/core workdir
cp .env.template .env

and edit .env according to your needs.

Name Description Default Type
PORT Defines port number the server will listen to for incoming connections. 3100 number
NODE_ENV Controls build optimization and enables some additional logging when set to development development "development" | "production"
DATABASE_URL Database connection string postgres://localhost/bloom string
REDIS_TLS_URL Secure Redis connection string string
REDIS_URL TCP Redis connection string redis://127.0.0.1:6379/0
REDIS_USE_TLS Flag controlling the use of TLS or unsecure transport for Redis 0 0 | 1
THROTTLE_TTL Rate limit TTL in seconds (currently used only for application submission endpoint) 60 number
THROTTLE_LIMIT Max number of operations in given time window THROTTLE_TTL after which HTTP 429 Too Many Requests will be returned by the server 2 number
EMAIL_API_KEY Sendgrid API key (see sendgrid docs for creating API keys SOME-LONG-SECRET-KEY string
EMAIL_FROM_ADDRESS Controls "from" field of all the emails sent by the process 'Bloom Dev Housing Portal bloom-no-reply@exygy.dev' string
APP_SECRET Secret used for signing JWT tokens (generate it with e.g. openssl rand -hex 48) SOME-LONG-SECRET-KEY string

Migrate and seed the DB

  1. Migrate the DB to latest schema:
    # backend/core workdir
    yarn run db:migration:run
    
  2. (Optional) Seed the database
    yarn db:migration:seed
    
    This step will create example listings, admin@example.com:abcdef admin user account, leasing agents user accounts etc.

Running the server

Development:

yarn run dev

Production:

yarn run build && yarn run start

Verifying if your setup works:

Go to localhost:3100/docs page and see if you can e.g. log in using /auth/login endpoint using following payload:

{
  "email": "admin@example.com",
  "password": "abcdef"
}

To play with other endpoints that require authentication copy paste the access token from the response to above query into the "Authorize" popup at the top of the page.