Making dotenv variables globally available
See original GitHub issueI was wondering if there was any way to make the variables in the .env
file globally available throughout my entire java application.
It seems as though configuring and loading the variables returns a Map
of sorts from which you can retrieve all of the values. However I have to configure and load this variable in every file from which I wish to use it.
Dotenv env = Dotenv.configure().directory("./").load();
Is there any way I can load them once and use them everywhere? Perhaps even through the native System.getenv()
static method? Running the configuration and loading once from my public static main
method or something.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to Use Node Environment Variables with a DotEnv File ...
Environment variables are supported out of the box with Node and are accessible via the env object (which is a property of the...
Read more >Master environment variables on Node.js with dotenv-expand
js process starts at runtime, it will automatically provide access to all existing environment variables, by creating an object (env from now on) ......
Read more >Managing Environment Variables in Node.js with dotenv
With Node.js apps, environment variables are available through the process.env global variable. We can set the environment variables before we ...
Read more >Using dotenv package to create environment variables - Medium
One solution for this is to use environment variables. These are local variables that are made available to an application. Creating these ...
Read more >How to use environment variables with Node.js - dotenv tutorial
Dotenv is a zero-dependency module that loads environment variables from a . env file into process. env. Storing configuration in the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I build my own little
util
class if you’re interested. I used this class to normalise the configuration forDotenv
throughout my app too.@jessevdp are you using a framework? If not, your
Config
class might have to do. But if yes, you might want to find a way to fit dotenv into there in a properly integrated fashion. Here is my example using Spring https://github.com/paulschwarz/spring-dotenvBeyond a simple static helper, I’m not sure that java-dotenv should do too much.