Environments

Environment Setup

There are 3 environments configured by default: development, staging, and production. Each environment can be run by executing its respective command:

  • yarn start:dev

  • yarn start:staging

  • yarn start:prod

Warning: To run yarn start:prod it's needed to run yarn build before.

Each environment uses their own.env file with the extension of the stage. The defaults are .env.development, .env.staging, and .env.production.

To run the base project, you will need at least the database configuration in an .env file.

Example:

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=examplePassword
DB_DATABASE=linker_backend_db
DB_SYNCHRONIZE=true

If you’re planning to use Docker Compose (optional), you will need to add additional environment variables for the database configuration.

# …env.development variables
POSTGRES_USER=postgres
POSTGRES_PASSWORD=examplePassword
POSTGRES_DB=linker_backend_db

Then, you can start Docker Compose with this command:

docker compose --env-file ./.env.development up

All the values from this Docker Postgres configuration should match the values from the API database configuration mentioned before.

You can read more about docker compose environment variables at this link.

Adding new environments

You can add new environments by adding a new script to the package.json file.

For example, to add a QA environment you can add to the package.json file the following: "start:qa": "cross-env STAGE=qa nest start" in the script section.

This will automatically read environment variables from a .env.qa file.

cross-env is a package to set runtime environment variables on Mac, Windows, and Linux.

Last updated