This repository contains source code for the above mentioned API.
This setup assumes you have a unix based system (Linux/OSX). For windows users, highly recommended to use the Windows Subsystem for Linux (WSL).
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.
Once node is installed, run the following in your terminal to install dependencies as defined in the package.json
file:
npm install
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.
Instead of a .env
file:
- You only need one environment variable
NODE_ENV
. Set this value todevelopment
- In the
config
folder, create adevelopment.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 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.
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.
On any code modifications, ensure your changes adhere to the project's code formatting standards as defined in .prettierrc
:
npm run prettier
Ensure any Typescript code changes compile by running the following on your terminal:
npm run compile
Start the backend server on your local machine (with hot-reloading) by running the following on your terminal:
npm run dev
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.
config/custom-environment-variables.json
: If environment variable is set, it will always take precedence first. Use for sensitive information.config/production.json
: IfNODE_ENV
isproduction
(alsodevelopment
orstaging
allowed) and a value is also indefault.json
, the value fromproduction.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.
config/custom-environment-variables.json
: If environment variable is set, it will always take precedence first. Use for sensitive information.config/production.json
: IfNODE_ENV
isproduction
and a value is also indefault.json
, the value fromproduction.json
will be used. Use for non-sensitive production options.config/default.json
: Takes the least precedence.