Skip to main content

Overview

Environments in Bruno allow you to define variables that can be used across your API requests. You can create multiple environments (like Local, Staging, Production) and switch between them easily.
Environment files are stored as .bru files in the environments/ folder within your collection.

Environment Structure

Environments are stored in your collection’s environments/ folder:

Creating Environments

Basic Environment

Here’s a simple environment file from the Bruno source:
Local.bru

Production Environment

Prod.bru

Development Environment

dev.bru

Secret Variables

Mark sensitive values as secrets to prevent them from being accidentally committed:
Local.bru
Variables listed in the vars:secret block are marked as sensitive. Bruno will warn you before committing files that contain secret values.

Using Environment Variables

Reference environment variables using double curly braces:

In Request Body

In Scripts

Runtime Variables

Set temporary variables during request execution that don’t persist:

Persisting Environment Variables

Update environment variables from scripts and persist them to the environment file:
api-setEnvVar-with-persist.bru
Use { persist: true } to save the variable value to the environment file. Without this option, variables are only available during the current session.

Post-Response Persistence

Deleting Environment Variables

Remove environment variables from scripts:
api-deleteEnvVar.bru

Multiline Variables

Define multiline values using triple quotes:
Test.bru
Use multiline variables in your requests:

Variable Interpolation

Variables can reference other variables:

Process Environment Variables

Variable Scope and Priority

Bruno resolves variables in this order (highest to lowest priority):
1

Runtime Variables

Variables set with bru.setVar() during request execution
2

Environment Variables

Variables defined in the active environment file
3

Collection Variables

Variables defined in collection.bru or folder.bru
4

Process Environment Variables

System environment variables accessed via {{process.env.VAR_NAME}}

Environment API

Bruno provides a JavaScript API for working with environments:

Non-String Values

Environment variables support various data types:
Stage.bru
Access in scripts:

Global Environments

Bruno also supports global environments that are available across all collections. Global environment files are stored outside your collection folder.
Global environments are useful for system-wide settings like proxy configuration or credentials that are used across multiple collections.

Color Coding

You can assign colors to environments for visual identification:

Best Practices

Use Secrets

Mark sensitive values as secrets in the vars:secret block

Environment Per Context

Create separate environments for local, staging, and production

Descriptive Names

Use clear variable names like apiBaseUrl instead of url1

Version Control

Commit environment templates, but keep actual secrets in local files

Example: Complete Environment Setup

Here’s a comprehensive example showing multiple environments:
Local.bru
Production.bru

Next Steps

Collections

Learn about organizing requests in collections

Bru Language

Master the .bru file format

Scripting

Use JavaScript to manipulate variables dynamically

Git Integration

Version control your environments