Setting HANAMI_ENV allows your code to act differently, depending on the environment.

If HANAMI_ENV is not set, Hanami will fallback to checking RACK_ENV. If neither variable is set, the environment defaults to :development.

By convention, Hanami expects HANAMI_ENV to be either development, test, or production.

Hanami.env returns a symbol representing the current environment.

  1. # HANAMI_ENV=test
  2. Hanami.env
  3. => :test

Hanami.env?

returns true if the given name(s) match the current environment.

  1. # HANAMI_ENV=development
  2. => true
  3. Hanami.env?(:test)
  4. => false
  5. Hanami.env?(:production)
  6. => false

You can match on more than one environment:

  1. # HANAMI_ENV=test
  2. Hanami.env?(:development, :test)
  1. # config/app.rb
  2. module Bookshelf
  3. class App < Hanami::App
  4. environment(:production) do
  5. # Production specific config or initialization
  6. config.middleware.use ProductionOnlyMiddleware
  7. end
  8. end
  9. end

See the for information on supported config options.

When deploying your application to production, set the HANAMI_ENV environment variable to production.

In production, Hanami logs to standard out by default, using a structured JSON format with a log level of :info rather than , which is used in development and test. See the for more detail.