How to Access Environment Variables In Clojure - Luminus Web Framework

2.8k Views Asked by At

I need help accessing my environment variables. I have :my-variable "value" in dev-config.edn and I'm trying to access it in another place. I required [my-app.config :refer [env]] and trying the following:

(defn my-function []
  (def variable (-> env :my-variable))
  (println (str "my environment variable: " variable)))

I tried this and several other things... What's the right to do this?

1

There are 1 best solutions below

0
Biped Phill On BEST ANSWER

Clojure can read environment variables via Java, so try this:

(System/getenv "my-variable")

Environment variables are strings, as far as Java is concerned. Whatever reads "dev-config.edn" converts your :my-variable keyword to a string. Perhaps this is it: https://github.com/yogthos/config . It mentions some details of the conversion, including "names lowercased, then _ and . characters converted to dashes".