Skip to content

4. Configuration

Ayush Goyal edited this page Aug 18, 2022 · 1 revision

This repo uses shared configuration that lives in the config folder. This is the central location where all external credentials and environment variables are read and loaded into a TypeScript config object. This config object can then be imported across the other packages where the variables can be used in a typed and predictable way.

Dev & Prod Environments

There is a clear distinction between development and production configuration as noted by the two separate dev.ts and prod.ts files. Each of these files match the same config schema but contains different information for their respective environment.

However, there exists a CommonConfig that is the same regardless of the environment. This contains information like our social media handles that don't change.

Description

This package sets up 3 main things:

Environment Variables

Development: It loads all your set environment variables from the .env file using a library called dotenv.

Production: Reads them directly through process.env

Google Credentials

Initializes Google Cloud and Firebase Admin by reading your Google credentials. These credentials authenticate your services with Google Cloud through an IAM service account and allow access to all things Google Cloud (identity platform, storage, firebase, etc.).

Development: The GOOGLE_APPLICATION_CREDENTIALS environment variable must be set with the path to your google-cloud-credentials.json.

Production: The application credentials are automatically provided when running in a Google production environment. Thus, we won't need to do any extra steps.

General Config

Everything else is general configuration that needs to be manually specific. These could include service specific info like database connection info, service URLs, port numbers, and API keys. Or general information like social media handles and Google Cloud project name.

Development: All config used for development lives in the dev.ts file.

Production: All config used for production lives in the prod.ts file.

Modifying the Config

When you want to modify the config, you'll need to make sure to update both environments. First, if you need to make a change to the schema, you'll want to edit the types.ts file. Then, you can go ahead and edit the respective environment files.