Mastering Hoppscotch Environment Variables: Reusable Values, Scoped Overrides, and Secure Sharing
Hoppscotch’s environment variables let you store reusable values like API keys, switch between dev/stage/prod, and even generate dynamic data with pre‑request scripts. Learn how to create, export, import, and use them safely, plus key trade‑offs to watch out for.
21 Nov 2025, 19:12 UTC

Why Environment Variables Matter in Hoppscotch
When you’re testing APIs, you often need to swap values like API keys, base URLs, or user IDs between environments—development, staging, and production. Hoppscotch’s environment variable system lets you store these values once and reference them everywhere. It keeps your request payloads tidy, reduces copy‑paste errors, and makes it easy to share consistent configurations with teammates.
Getting Started: Create an Environment and Add a Variable
- Open the Environment Manager (click the gear icon in the sidebar). This opens a modal where you can create, edit, and delete environments.
- Create a new environment named
Development. Click + New Environment and give it a descriptive name. - Add a variable:
- Key:
apiKey - Value:
12345-ABCDE(replace with your real key)
- Key:
- Click Save to persist the environment.
Using the Variable in a Request
1. Create a new GET request to https://api.example.com/resource?key={{apiKey}}. The double‑curly braces syntax tells Hoppscotch to replace {{apiKey}} with the value stored in the active environment.
2. Make sure the Development environment is selected in the top‑right dropdown.
3. Hit Send. In the request preview you should see the URL rendered as https://api.example.com/resource?key=12345-ABCDE. The response will contain whatever data the API returns.
Exporting and Importing Environments for Version Control
Environment files are JSON objects that can be checked into source control or shared via email. This keeps teammates on the same page without revealing secrets in a public repo.
- Export: In the Environment Manager, click the gear icon next to
Developmentand select Export. Adevelopment.jsonfile is downloaded.- Sample structure:
{ "name": "Development", "variables": { "apiKey": "12345-ABCDE" } }
- Sample structure:
- Delete the local environment (to simulate a new machine).
- Import: Click Import Environment in the manager, choose the downloaded JSON, and confirm. The
Developmentenvironment reappears with the same variable. - Run the same request again to verify the variable is restored.
Dynamic Variables with Pre‑Request Scripts
Sometimes you need a value that changes on each request, such as a timestamp or a signed token. Hoppscotch lets you run JavaScript before the request is sent.
- Open the request you created earlier.
- Switch to the Pre‑Request Script tab.
- Add the following code:
// Set a timestamp variable pm.variables.set("timestamp", Date.now()); - In the request body (or URL), reference
{{timestamp}}. - Send the request. Open the console (Ctrl+Shift+J in most browsers) and you should see logs confirming the variable was set. The URL or body will now contain a millisecond‑precision timestamp.
Trade‑offs and Limitations
- Plain‑text storage: Variables are stored as plain text in the UI and exported JSON. If you share a file publicly, secrets can leak. Use environment‑specific files and keep them out of version control, or encrypt them with tools like
git-crypt. - Performance impact: A very large number of variables or complex pre‑request scripts can add latency to request execution. Monitor the request timeline if you notice delays.
- No built‑in secret masking: Unlike some other tools, Hoppscotch does not mask variable values in the UI. Be careful when sharing screenshots or logs.
Actionable Checklist
- Define a dedicated environment file for each stage (dev, staging, prod).
- Keep sensitive variables out of public repositories—use separate, encrypted files.
- Use pre‑request scripts sparingly; keep them simple to avoid slowdowns.
- Export environments regularly and store them in a secure location or shared drive.
- On each new machine, import the relevant environment and set it as active before running tests.
By treating environment variables as first‑class citizens in your API testing workflow, you reduce duplication, improve consistency, and keep sensitive data under tighter control.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.