logo Buffalo slack logo
Getting Started


In this chapter, you’ll learn how to manage configuration with Buffalo.

Environment variables are a good way to separate environment specific values, or secrets, from your application code base (as described in The Twelve Factor app). It can help define behavior that is based on the context of the app (as requiring SSL on production) and isolate secrets from your code base. This way, all developers don’t have to know the productions keys to sensitive services, such as a bank API, and they can use sandbox API keys.

Available Environment Variables

The following variables are used by Buffalo:

Variable Default Usage
GO_ENV development The environment (dev, qa, production etc.) that Buffalo is run in.
GO_BIN go The Go compiler to use.
BUFFALO_PLUGIN_PATH $PATH Where Buffalo looks for plugins.
BUFFALO_PLUGIN_TIMEOUT 1s How long Buffalo waits for a plugin to respond.
ADDR or Which address to bind the server to.
PORT 3000 Which port to bind the server to.
HOST$PORT The “URL” of the application (i.e. what end users type in).
SESSION_SECRET "" A salt used for securing sessions.

Custom Configuration

You still can provide your own variables, and retrieve them from within your application. The envy package makes it easy!

import "github.com/gobuffalo/envy"

// [...]

// Get MYSECRET env variable, default to empty string if it's not set
var MYSECRET = envy.Get("MYSECRET", "")

// Get REQUIREDSECRET env variable, return an error if it's not set

Support for .env Files

Buffalo ships with .env support (since buffalo >= 0.10.3), meaning buffalo will load .env files into environment variables once the application starts. To do it, Buffalo uses envy.Load which will look for .env file at the root of your app.

If you’re not familiar with how a .env file looks, here is an example:



Generated apps (with buffalo >= 0.10.3) will also create a default .env file in your application root. This file will be watched by Buffalo for changes, but will be ignored by git (added in the .gitignore). This is a good way to prevent developers to push credentials by mistake.

Next Steps