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:
If you’re planning to use Docker Compose (optional), you will need to add additional environment variables for the database configuration.
Then, you can start Docker Compose with this command:
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