keyshade
keyshade copied to clipboard
Add environment inference in backend
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
inapps/api/src/common
- Add all the environment variable names mentioned in
.env.example
inenvironment.ts
- Refactor all usage of
process.env.NAME
toEnvironment.NAME