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
-
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.
As I previously said I am confused which approach should I follow as this one fails to meet my requirements to directly access env variables from packages folder. Does having .env in the
apps/
at root the solution? How should I handle db credentials as well?if .env is placed at root, then I would have to do something like this which I don't think is the best practice maybe:
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
Please do point me out if what I wanted was little confusing or off the mark.
References:
Example
https://github.com/CosmoWorker/Turbo-repo-Chat
Beta Was this translation helpful? Give feedback.
All reactions