Typing the same base URL and token into every request gets old quickly — and it’s risky when you switch between a test server and production. Environments solve this. An environment is a named set of variables, and you can switch between environments with one click.

How variables look

In Hoppscotch, you reference a variable by wrapping its name in double angle brackets:

<<baseUrl>>/users/<<userId>>

Variables work in the URL, parameters, headers, authorization fields and request body.

Create your first environment

  1. Open the Environments panel from the sidebar.
  2. Create a new environment and name it Local.
  3. Add a variable baseUrl with the value http://localhost:3000.
  4. Create a second environment named Staging with baseUrl set to your staging address, for example https://staging.example.com.
  5. Select an environment from the environment selector near the top of the screen.

Now a request to <<baseUrl>>/health goes to localhost or staging depending on which environment is active. Hovering over a variable shows the value it currently resolves to.

Global variables

Besides named environments there is a Global environment. Its variables are available whichever environment is selected. It’s a good place for values that never change between servers, such as a test user’s email. If a named environment defines a variable with the same name, the named one wins.

Keeping secrets safe

  • Recent versions let you mark a variable as secret. Secret values are hidden on screen and are kept on your device rather than being synced to the cloud or shared with your team. Check the environment editor in your version for this option.
  • Never put production passwords in a collection you export or share. Use variables and keep the real values in your own environment.
  • When sharing an environment with teammates, share the variable names and let each person fill in their own tokens.

Set variables automatically with scripts

A common pattern is logging in once and reusing the token. Add this to the Tests (post-request script) tab of your login request:

// after a successful login response like {"token": "abc..."}
pw.env.set("token", pw.response.body.token);

Then use Bearer <<token>> in the authorization of your other requests. You can also prepare values before sending in the Pre-request script tab:

pw.env.set("requestTime", Date.now().toString());

Scripts are covered in detail in Pre-request scripts and tests. Hoppscotch’s scripting API keeps growing, so check the official docs for helpers available in your version.

Import and export

Environments can be exported to a JSON file and imported elsewhere — useful for the Hoppscotch CLI, which accepts an environment file when running a collection.

Troubleshooting

  • The variable is sent literally as <<baseUrl>> — no environment containing it is selected, or the name has a typo. Names are case-sensitive.
  • The wrong value is used — check whether the same name exists in both the Global and the selected environment.
  • A teammate gets a different result — they may have a different environment selected. Ask them to hover over the variable to confirm its value.