Managing environment variables across the project #10064
Unanswered
CosmoWorker
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I am trying to understand how the environmental variables need to be handled. I see in the docs that .env files should be used in the packages where they are used.
I come across some suggestions over the internet that having .env in the root might be helpful to share across multiple applications. But I also came across usage of packages folder for keeping common content such as config, schema, and the database part (ORM).
For Context, consider my current file structure (inspired):
I have my environmental variables setup in backend-common with config(exported). So When I try to import it in one of the server, I cannot run the server as env variables are loaded in the config rather than the application which is server.
Example Code
Update -- Please do check Repo
The issue doesnt seem to be the placement of .env either in root of apps/ folder or placing it individually in each project(like http-server, ws-server, web) within apps/ folder. Here the importing of a config from a packages folder when used is built first thus the variables are not loaded despite dotenv.config being used in the index.ts file of http-server.
Config.ts (Exported from packages folder's backend-common)
Ex1 - index.ts
Output
Ex2- index.ts
output
What do I do now to resolve this issue despite having the env setup right I am not able to load it when I am trying to use config.ts which I exported from packages folder
How should I handle db credentials as well because there is .env there as well by ORM?
Please do point me out if what I wanted was little confusing or off the mark.
References:
Repo
https://github.com/CosmoWorker/Turbo-repo-Chat
Beta Was this translation helpful? Give feedback.
All reactions