Skip to main content

bud.env

bud.js includes support for utilizing dotenv values in your configuration, html templates and application code.

Environment variable values are sourced from an .env file located in the project root.

Accessing env values from the config file

Values defined in the application .env file are available via bud.env.

The bud.env object is a container instance.

Most commonly you'll probably find yourself using these methods:

bud.env.get('APP_NAME')
bud.env.is('APP_ENV', 'production')

Accessing env values from within a template

Values defined in the application .env file are available within HTML templates. See bud.html usage details.

Accessing env values from within the application

Any .env values with a key starting with PUBLIC_ will be available within the application globally.

.env
PUBLIC_APP_NAME="My App"

The PUBLIC_APP_NAME envvar will be available as APP_NAME in application source files. This replacement is static, and happens during the build.

console.log(APP_NAME)