Can I load a .env file for a module instead of the whole project?

There are some utils for loading .env files, can this support the above? Or do I need to use my own solution here.
Solution:
I see what you mean, I'll change the working directory in the IDEA run configuration
Jump to solution
46 Replies
gdude
gdude•2mo ago
What's your use-case specifically? .env is a standard and is parsed at runtime, so I'm curious what you're trying to do here
Ratledore
Ratledore•2mo ago
My bot is in a module, not the root project, the .env in my module isn't being loaded
gdude
gdude•2mo ago
the .env must be located in your current working directory otherwise, yeah, it won't find it dotenv is a sort of informal standard - it's a key-value file, it supports line comments, and it must be placed in the current working directory (it's not a kordex thing, we just provide a util for it)
Ratledore
Ratledore•2mo ago
I have seen implementations in the past where multiple .env files are supported for sub projects, with descending priority etc No worries - I'll have to implement something else then
gdude
gdude•2mo ago
I'm not really sure of the context you're working with it doesn't make sense to me to ask for a .env for a subproject because that implies you're resolving it at compile-time whereas .env is intended for users to fill out for run-time configuration
Ratledore
Ratledore•2mo ago
It's being used as a dev runtime configuration
gdude
gdude•2mo ago
is there a reason you can't put it in your cwd? I guess I could make the util check the classpath that doesn't seem very useful, though
Solution
Ratledore
Ratledore•2mo ago
I see what you mean, I'll change the working directory in the IDEA run configuration
gdude
gdude•2mo ago
yeah I mean for dev you'd probably just put it in your project root and gitignore it
Ratledore
Ratledore•2mo ago
There are multiple modules which have separate .env files
gdude
gdude•2mo ago
I see
Ratledore
Ratledore•2mo ago
This works now,thanks
gdude
gdude•2mo ago
no worries, but if you can think of an approach that might help out better, I'm happy to look into it
Ratledore
Ratledore•2mo ago
This is an implementation I saw on some typescript framework a while back, it seemed nice and intuitive for me.
root
.env
|----moduleA
.env
|----moduleB
.env
root
.env
|----moduleA
.env
|----moduleB
.env
if I run moduleA, .env from root and .env from moduleA are loaded, overwriting the root environment.
gdude
gdude•2mo ago
so moduleA is executable as well?
Want results from more Discord servers?
Add your server