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:Jump to solution
I see what you mean, I'll change the working directory in the IDEA run configuration
46 Replies
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 hereMy bot is in a module, not the root project, the .env in my module isn't being loaded
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)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
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
It's being used as a dev runtime configuration
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
I see what you mean, I'll change the working directory in the IDEA run configuration
yeah I mean for dev you'd probably just put it in your project root and gitignore it
There are multiple modules which have separate .env files
I see
This works now,thanks
no worries, but if you can think of an approach that might help out better, I'm happy to look into it
This is an implementation I saw on some typescript framework a while back, it seemed nice and intuitive for me.
if I run moduleA,
.env
from root
and .env
from moduleA
are loaded, overwriting the root environment.so
moduleA
is executable as well?