Skip to content

Source Code For Core Backend API For BetterSteps Platform

Notifications You must be signed in to change notification settings

nigelnindodev/bettersteps-core-api

Repository files navigation

Better Steps Core API

This repository contains source code for the above mentioned API.

Setup

This setup assumes you have a unix based system (Linux/OSX). For windows users, highly recommended to use the Windows Subsystem for Linux (WSL).

Dependencies Installation

Install Node Runtime

Install Node JS & NPM on your system. The application uses the latest stable long term support (LTS) version Node JS. Use the latest version of NPM available.

Highly recommended to use Node Version Manager (NVM) to easily switch between Node JS versions. See Option 3 on this article.

Install Project Specific Dependencies

Once node is installed, run the following in your terminal to install dependencies as defined in the package.json file:

npm install

Development Workflow

Development workflows should be run after successful installation of dependencies.

Development workflows use npm run scripts. Check package.json for specific details of each script.

Database Migrations

Database Credentials

Instead of a .env file:

  • You only need one environment variable NODE_ENV. Set this value to development
  • In the config folder, create a development.json file.

Example contents of development.json (use credentials for your local PostgreSQL instance):

{
  "postgresql": {
    "client": "pg",
    "connection": {
      "host": "localhost",
      "port": 5432,
      "database": "bettersteps_db",
      "user": "bettersteps_backend_pg_user",
      "password": "bettersteps_db_password"
    }
  }
}

See application configuration section for more details.

Database Migrations

Database migrations run on server start, no additional process is required.

To create new migrations, make required changes to src/database/schema.ts file then create the migration.

NB: Do not create migrations directly to staging or production databases. Create the migration locally, and make a Pull Request. The migration will be appliad automatically on server start.

Create New Migration

Simply run:

npm run migration-create

The npm command above is alias for drizzle-kit generate which will check the database schema and auto create migration.

Code Formatting & Linting

On any code modifications, ensure your changes adhere to the project's code formatting standards as defined in .prettierrc:

npm run prettier

Code Compilation

Ensure any Typescript code changes compile by running the following on your terminal:

npm run compile

Start Backend Development Server

Start the backend server on your local machine (with hot-reloading) by running the following on your terminal:

npm run dev

Application Configuration

The application configuration uses node-config to provide application configuration values.

node-config reads configuration values by default from config/default.json file. Based on value of NODE_ENV environment file, this might be read from config/production.json. Set value of NODE_ENV to either development, staging or production.

There are cases where there are sensitive environment variables that should not be stored in JSON files. These should be specified in config/custom-environment-variables.json. See file usage in the project for example usage, and documentation for additional information.

Order Of Configuration Precedence (Most Precedent List First)

  • config/custom-environment-variables.json: If environment variable is set, it will always take precedence first. Use for sensitive information.
  • config/production.json: If NODE_ENV is production (also development or staging allowed) and a value is also in default.json, the value from production.json will be used. Use for non-sensitive production options.
  • config/default.json: Takes the least precedence.# Application Configuration The application configuration uses node-config to provide application configuration values.

node-config reads configuration values by default from config/default.json file. Based on value of NODE_ENV environment file, this might be read from config/production.json. Set value of NODE_ENV to either development or production.

There are cases where there are sensitive environment variables that should not be stored in JSON files. These should be specified in config/custom-environment-variables.json. See file usage in the project for example usage, and documentation for additional information.

Order Of Configuration Precedence (Most Precedent List First)

  • config/custom-environment-variables.json: If environment variable is set, it will always take precedence first. Use for sensitive information.
  • config/production.json: If NODE_ENV is production and a value is also in default.json, the value from production.json will be used. Use for non-sensitive production options.
  • config/default.json: Takes the least precedence.

About

Source Code For Core Backend API For BetterSteps Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages