Lucee 5: simpler access to environment variables

18 October 2017

Lucee 5 has been out for nearly a year and a half now, but various critical issues have prevented us from completing our upgrade from 4.5. Happily these problems seem to have been resolved and the current version is looking very stable in production.

Most of the development effort in version 5 went into rewriting the engine from the ground up around the OSGi model, so the number of new features is small. But there are a few improvements worth noting and I'm expecting this to be the first in a short series of posts on what I'm finding useful.

Environment variables

I first became aware of the importance of using environment variables (or "env vars") for configuration in the 12 factor app. but it's taken me a while to appreciate their value in decoupling the code base from its deployment environment.

Prior to Lucee 5, accessing env vars wasn't difficult but did mean reaching into the underlying java:


system = CreateObject( "java", "java.lang.System" );
dbPassword = system.getEnv( "DB_PASSWORD" );

In version 5, Lucee exposes all system env vars in a new environment struct in the server scope. So to get our db password we now just need:


dbPassword = server.system.environment.DB_PASSWORD;

Posted by Julian on .

Comments

  • Formatting comments: See this list of formatting tags you can use in your comments.
  • Want to paste code? Enclose within <pre><code> tags for syntax higlighting and better formatting and if possible use script. If your code includes "self-closing" tags, such as <cfargument>, you must add an explicit closing tag, otherwise it is likely to be mangled by the Disqus parser.
Back to the top