dotenv: Read enviroment variables from a .dotenv or straight from your OS

You might find it useful or not. It depends on what you can imagine it to be used with, like I had to.

Either way, I created a lib that can fetch environment variables from a file or from the OS where Caché is running.

Mostly know as dotenv. Many languages have it, so why not Caché?

The usage is pretty simple:

If you want to use OS env vars exclusively, just use the method:

##class(DotEnv.Parser).FromOS()

Otherwise, if you want to specify a .env file containing your variables to complement the OS ones use the method:

##class(DotEnv.Parser).FromPath("/path/to/file")

Both methods return an %ArrayOfDataTypes containing the env variables.

  • + 1
  • 0
  • 241
  • 2
  • 1

Answers

Thank you!

Here's a method to get OS environment variable:

write $System.Util.GetEnviron(VariableName)

Oh crap! I knew I had seen it somewhere.

EDIT: Ahh, btw... it's Util, not Utils.