A Clojure library designed to make working with environment variables easier. It borrows ideas from environ, but is friendlier for using non-checked-in user-specific .env
files (similar to the Ruby dotenv gem), and allows simple dynamic augmentation of environment variable values. It does not support .lein-env
integration.
Envvar resolves variable sources in the following order (lower numbers have priority, so dynamic overrides have highest priority):
- Dynamic overrides.
- Anything in user-loaded Java properties files.
- Values in the
.env
file in the project (a Java properties file). - Java system properties.
- Environment variables.
(require '[envvar.core :as envvar :refer [env with-env]])
;; return all environment variables as a map:
@env
;; return the value of the PATH environment variable:
(:path @env)
;; augment the environment:
(with-env [:one "hello", :two "world"]
;; @env will now also contain dynamically-scoped bindings for :one and :two
)
;; load more properties into the environment
(envvar/load-file-variables! "/path/to/properties.file")
;; reset all loaded properties, including ones from the .env file
(envvar/reset-file-variables!)
[envvar "1.1.2"]
<dependency>
<groupId>envvar</groupId>
<artifactId>envvar</artifactId>
<version>1.1.2</version>
</dependency>
Distributed under the Eclipse Public License version 2.0.