Skip to Content
FeaturesEnvironmentsOverview

Environments

Store values such as base URLs, tokens, and IDs as variables, then reference them in any request. Switch environments to run the same requests against development, staging, or production.

The Global and Local environments and .env files are available only in the paid version.

Use Variables

Reference a variable with the {{variableName}} format.

{{variableName}}Works inQuery ParamsHeadersBodyTests

Common Variables

The following variables are available for all requests without defining them in an environment.

VariableValue
{{request_name}}Name of the current request
{{collection_name}}Name of the collection the request belongs to
{{folder_name}}Name of the folder the request belongs to

Environment Options

The numbered options in the image are referenced in the sections below.


Thunder Client Environment Variables

Variable Precedence

When a variable is defined in more than one place, the value from the higher level wins. Levels are listed from lowest to highest precedence.

  1. OS Environment Variables

    Reference OS environment variables as global variables using the format {{variable}}.

  2. Global EnvironmentPaid

    Store variables that can be accessed across all collections. These values are saved in the tc_env_global.json file (option 2 in the image).

  3. Local EnvironmentPaid

    Save secrets and transient tokens locally on your computer, which is useful for excluding secrets from a Git project. This environment is a global type, and its variables are available to all collections (option 3 in the image).

  4. .env FilesPaid

    Link a .env file to an environment:

    • Create an environment (option 1 in the image).
    • Open the Environment view and select Link to .env file.
    • Select the .env file and save. You can now use its variables in requests with {{variable}}.

    The variables in the .env file use this format:

    .env.sample
    key=value name=thunder number=25543
  5. Active Environment

    To use an environment’s variables, make it active from the options menu ... by selecting Set Active. See Active Environment.

  6. Collection and Request Variables

    Set collection- and request-specific variables in scripting using the request scope. These values are available only while the request runs. Open collection settings or the request view, then select the Pre Run tab and use the Scripting tab.

    tc.setVar("name", "Thunder Client", "request"); tc.setVar("baseUrl", "http://localhost:8744", "request");

More on Environments

Last updated on