> ## Documentation Index
> Fetch the complete documentation index at: https://bruno-a6972042-docs-timeline-scripts.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Variables

### Overview

Variables in the Bruno allow you to store dynamic values that can be reused across multiple API requests, environments, and workflows. This feature enhances flexibility, maintainability, and efficiency by enabling you to manage frequently changing data points such as tokens, environment-specific URLs, or user-defined values in one place.

### Types

There are 6 types of variables you can create:

* [Global Environments Variables](./global-environment-variables)
* [Environment Variables](./environment-variables)
* [Collection Variables](./collection-variables)
* [Folder Variables](./folder-variables)
* [Request Variables](./request-variables)
* [Runtime Variables](./runtime-variables)

Additionally, Process Environment Variables can be defined in an external environment configuration file:

* [Process Environment Variables](./process-env)

Runtime variables get the highest precedence. Process Environment Variables are accessed using the `{{process.env.VAR_NAME}}` syntax and hence don't compete with the above.

### Variable Precedence and Scope

When a variable is accessed, the following precedence is used to determine which value is used:

<div style={{ display: 'flex', justifyContent: 'center', fontFamily: 'sans-serif', marginTop: '2em', width: '100%' }}>
  <div style={{ display: 'flex', alignItems: 'flex-start', position: 'relative', width: '420px' }}>
    <div style={{ position: 'absolute', left: '-120px', top: 0, height: '100%', display: 'flex', flexDirection: 'column', justifyContent: 'space-between', fontSize: '0.85em', color: '#555', textAlign: 'right', width: '120px' }}>
      <div style={{ paddingRight: '10px' }}>↑ Higher Precedence</div>
      <div style={{ paddingRight: '10px' }}>↓ Broader Scope</div>
    </div>

    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '300px' }}>
      <div style={{ fontWeight: 'bold', backgroundColor: '#e07f00', color: 'white', padding: '8px', width: '200px', borderRadius: '6px' }}>Runtime Variables</div>
      <div style={{ marginTop: '6px', backgroundColor: '#e88f1a', color: 'white', padding: '8px', width: '220px', borderRadius: '6px' }}>Request Variables</div>
      <div style={{ marginTop: '6px', backgroundColor: '#ee9f33', color: 'white', padding: '8px', width: '240px', borderRadius: '6px' }}>Folder Variables</div>
      <div style={{ marginTop: '6px', backgroundColor: '#f4aa4a', color: 'black', padding: '8px', width: '260px', borderRadius: '6px' }}>Environment Variables</div>
      <div style={{ marginTop: '6px', backgroundColor: '#f6b45d', color: 'black', padding: '8px', width: '280px', borderRadius: '6px' }}>Collection Variables</div>
      <div style={{ marginTop: '6px', backgroundColor: '#f8be70', color: 'black', padding: '8px', width: '300px', borderRadius: '6px' }}>Global Variables</div>
    </div>
  </div>
</div>

Runtime variables get the highest precedence. Process Environment Variables are accessed using the `{{process.env.VAR_NAME}}` syntax and hence don't compete with the above.

### Variable Storage

Each variable has its own storage location either within your collection file or within the app's memory. **All storage is local.**

<div style={{ display: 'flex', justifyContent: 'center', marginTop: '2em' }}>
  <table style={{ borderCollapse: 'collapse', width: '600px', fontFamily: 'sans-serif', border: '1px solid #ddd' }}>
    <thead>
      <tr style={{ backgroundColor: '#f4aa4a', color: 'white' }}>
        <th style={{ textAlign: 'left', padding: '8px', border: '1px solid #ddd', width: '50%' }}>Variable Type</th>
        <th style={{ textAlign: 'left', padding: '8px', border: '1px solid #ddd', width: '50%' }}>Storage Location</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Collection</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>`<collection-name>.bru`</td>
      </tr>

      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Folder</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>`<folder-name>.bru`</td>
      </tr>

      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Request</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>`<request-name>.bru`</td>
      </tr>

      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Environment</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>`<env-name>.bru`</td>
      </tr>

      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Runtime</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Local storage</td>
      </tr>

      <tr>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Global</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Local storage</td>
      </tr>

      <tr style={{ backgroundColor: 'rgba(128, 128, 128, 0.1)' }}>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%' }}>Process Environment</td>
        <td style={{ padding: '8px', border: '1px solid #ddd', width: '50%', fontStyle: 'italic' }}>Separate `.env` file</td>
      </tr>
    </tbody>
  </table>
</div>

### Variable Data Type

All variables are stored as strings. Bruno does not infer or change the data type of the variable based on the value you set.

### Debugging Variables in Console

You can access and debug variables in the console using the following pattern:

The pattern follows `bru.get[Type]Var(key)` where:

* `[Type]` is the variable type (Runtime, Request, Folder, etc.)
* `key` is the variable name you want to access

#### Example:

```javascript theme={null}
// Basic syntax: console.log(bru.get[Type]Var(key))
console.log(bru.getVar('myVar'))           // Runtime variables
```

### Scripting API

Please see the [Scripting API](/scripting/javascript-reference#collection-variables) for more information on how to access variables in your scripts.
