keyshade icon indicating copy to clipboard operation
keyshade copied to clipboard

Add environment inference in backend

Open rajdip-b opened this issue 10 months ago • 27 comments

Description

Accessing environmental variables from using process.env.NAME is a pain. To ease reusability of these environments, and proper inference, we would like to add an object that will fetch the environment values on our behalf.

Solution

The solution looks something like this:

export const Environment = {
  DATABASE_URL: process.env.DATABASE_URL!
}

This is the environment.ts file that will go in apps/api/src/common. The DATABASE_URL is already mentioned in the .env file, all we are doing here is making a proper inference of it.

This issue requires you to do the following things:

  • Create a environment.ts in apps/api/src/common
  • Add all the environment variable names mentioned in .env.example in environment.ts
  • Refactor all usage of process.env.NAME to Environment.NAME

rajdip-b avatar Apr 08 '24 09:04 rajdip-b