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?
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".