Blog

ColdBox Free Tip 7 - ENVIRONMENT Environment Variable

Victor Campos October 08, 2025

Spread the word

Victor Campos

October 08, 2025

Spread the word


Share your thoughts

ColdBox 102 Tips and Tricks by Luis Majano

Manage Multiple Environments in ColdBox

ColdBox offers a smart way to manage environments by auto-sensing an environment variable called ENVIRONMENT. This allows you to dynamically control the environment in which your application runs, streamlining your development, testing, and production workflows.

ENVIRONMENT Environment Variable

You can define the ENVIRONMENT variable in your .env file to specify which environment your ColdBox application should use. Here’s an example:

#.env file
ENVIRONMENT=development

Once ColdBox detects the ENVIRONMENT variable, it will automatically set the environment in the application and look for matching methods in your configuration files. By default, the environment is called production

How It Works

When the application starts, ColdBox will:

  1. Detect the ENVIRONMENT variable: If found, it sets the current environment to the value specified (e.g., developmentstagingproduction).

  2. Look for a matching method in ColdBox.cfc: The framework searches for a method in config/ColdBox.cfcwith the same name as the environment and executes it if found. For example, if ENVIRONMENT=development, ColdBox looks for a development() method in ColdBox.cfc.

  3. Search modules for matching methods: It also checks each module’s ModuleConfig.cfc file for methods matching the environment and executes them during startup.

Precedence

It’s important to note that the ENVIRONMENT variable in your .env file takes precedence over the environment struct in your ColdBox.cfc. So, if both are set, the environment variable will override the value in the config file.

Why Use the ENVIRONMENT Variable?

  • Flexibility: Easily switch between environments (development, staging, production) without modifying your codebase.

  • Automation: Automatically execute environment-specific configurations for both your application and modules.

  • Consistency: Ensures that your environments are defined and managed in a consistent way across all your applications and modules. This is a powerful feature to manage multiple environments in ColdBox. Set up your ENVIRONMENTvariable today and streamline your application’s environment management!

App Mode Helpers

ColdBox 7 introduces opinionated helpers to the FrameworkSuperType so you can determine if you are in three modes: production, development, and testing by looking at the environment setting:

Copy

function isProduction()
function isDevelopment()
function isTesting()
ModeEnvironment
inProduction() == trueproduction
inTesting() == truetesting
inDevelopment() == truedevelopment or local

You can also find these methods in the controller object.

Learn More ColdBox Tips and Tricks

Stay tuned for more ColdBox tips in our ongoing series. if you want to learn more than 10 free tips and tricks make sure to get your “ColdBox 102 tips and tricks book” We have a variety of formats you can choose from.

Get your Copy

Join the Ortus Community

Be part of the movement shaping the future of web development. Stay connected and receive the latest updates on, product launches, tool updates, promo services and much more.

Subscribe to our newsletter for exclusive content.

Follow Us on Social media and don’t miss any news and updates:

Add Your Comment

Recent Entries

12 Days of BoxLang - Day 4: TestBox

12 Days of BoxLang - Day 4: TestBox

Today we’re celebrating one of the most exciting new additions to the BoxLang ecosystem:

the TestBox BoxLang CLI Runner — a fast, native way to run your TestBox tests directly through the BoxLang Runtime. ⚡

No server required. No CommandBox needed. Just pure, ultra-fast BoxLang-powered testing from the command lineon Windows, Mac, and Linux.

If you’re building modern applications with BoxLang — web apps, CLIs, serverless functions, Android apps, or OS-level utilities — this new feature gives you a unified, flexible testing workflow you can run anywhere.

Victor Campos
Victor Campos
December 13, 2025
12 days of BoxLang - Day 3: SocketBox!

12 days of BoxLang - Day 3: SocketBox!

As BoxLang continues evolving into a modern, high-performance, JVM-based runtime, real-time communication becomes essential for the applications we all want to build: dashboards, collaboration tools, notifications, live feeds, multiplayer features, and more.

That’s where SocketBox steps in — the WebSocket upgrade listener built to work seamlessly with CommandBox and the BoxLang MiniServer. ⚡

Today, for Day 3, we’re highlighting how SocketBox supercharges BoxLang development by giving you fast, flexible, and framework-agnostic WebSocket capabilities.

Maria Jose Herrera
Maria Jose Herrera
December 12, 2025
12 Days of BoxLang - Day 2: CommandBox

12 Days of BoxLang - Day 2: CommandBox

BoxLang + CommandBox: The Enterprise Engine Behind Your Deployments

For Day 2 of our 12 Days of Christmas series, we’re diving into one of the most powerful parts of the BoxLang ecosystem: CommandBox the defacto enterprise servlet deployment platform for BoxLang.

If BoxLang is the language powering your applications, CommandBox is the engine room behind it all. ⚙️

Victor Campos
Victor Campos
December 11, 2025