skip to content

In Postman, what does an environment file contain, and how does a run read those values?

level: juniorimportance: must knowfreq 76%

answer

  1. Two files leave your machine, not one
  2. The values are not in the collection
  3. Three keys: id, name, values
  4. Each entry: key, value, type, disabled
  5. Loaded once into a VariableScope

basics

~20 s

A Postman environment file is a separate JSON document holding an id, a name and a values array of key, value, type and disabled entries. A run is pointed at one file and loads it as a variable scope.

solid answer

~40 s

An environment is its **own file**, not part of the collection. It carries an `id`, a `name` and a `values` array, and each entry in that array is one variable with `key`, `value`, `type` and `disabled`. An entry marked `disabled` is still written into the file rather than removed, so an exported file can hold values that take no part in a run. When a run starts it is pointed at exactly one such file and loads it into a `VariableScope` — the collection SDK's class for a named bag of variables — and scripts reach that scope through the sandbox's `pm.environment`. Because the values live outside the collection, the same collection document can be run against different targets by pointing it at a different file.

code

json · 9 lines
json
{
  "id": "3f7c1a90-2b44-4d8e-9f2a-6c1e5b0d7a11",
  "name": "staging",
  "values": [
    { "key": "baseUrl", "value": "https://staging.internal", "type": "string", "disabled": false },
    { "key": "accountId", "value": "acme-eu", "type": "string", "disabled": false },
    { "key": "legacyHost", "value": "https://old.internal", "type": "string", "disabled": true }
  ]
}

go deeper

for a junior

Be ready to say that a Postman environment is its own JSON file with an id, a name and a values array, and that the collection file does not contain it.

for a middle

Explain the entry shape — key, value, type, disabled — and that the run loads the file once into a VariableScope which pm.environment then reads and writes.

for a senior

Show you know an exported collection arrives without its values, and that a disabled entry stays in the file, so what is in the document is not the same as what a run uses.

for a principal

Own the artefact question: which value files exist, who may change them, and how a team keeps their key sets aligned so one collection stays runnable everywhere.

## What an environment file is A Postman **environment** is a JSON document that lives beside a collection rather than inside it. Its shape is small and fixed: an `id`, a `name`, and a `values` array. Everything a run reads out of an environment comes from that array — there is nothing else in the file a run consults. Each entry in `values` is one variable, and it carries four things: - `key` — the name a request or a script asks for. - `value` — what that name resolves to. - `type` — the entry's declared type. The collection format's `variable.type` enum is `string`, `boolean`, `any` and `number`. - `disabled` — a flag. An entry marked `disabled` is still **written into the file** rather than removed from it, which is why an exported file can carry entries that take no part in a run. That is the whole document. There is no request in it, no script, no folder, no auth block: an environment file is a **list of named values and nothing else**. ## The file, the scope and the sandbox handle Three things are easy to run together, and interviewers separate them on purpose: | Thing | Whose it is | What it actually is | |---|---|---| | the environment file | the exported document | `id`, `name` and a `values` array of entries | | `VariableScope` | the collection SDK | the in-memory object a run builds from those entries | | `pm.environment` | the script sandbox | `get`, `set`, `unset` and `clear` over that scope | A run does not read the file entry by entry each time a name is needed. It loads the file **once** into a `VariableScope` — the SDK's class for a named bag of variables — and from then on the scope is what answers. `pm.environment` is the sandbox's handle on that same scope, which is why a script can read a value the file supplied and write one the file never mentioned. ## Why the values sit in their own file The point of the separation is that the collection stays **one artefact** while the values change. The same collection document can be run against a scratch service, a shared test deployment, or a teammate's laptop, and the only thing that differs between those runs is **which environment file the run was pointed at**. Nothing in the requests forks per target, so a change to a request is made once. The consequences are worth stating plainly, because each one is a question in its own right: - **An exported collection does not carry an environment.** Two files leave your machine, or the person you hand it to gets requests with no values behind them. - **A run is pointed at one environment.** Environments are not merged with each other; you choose the file, not a stack of files. - **Two environment files may define the same `key` with different values.** That is the entire point — `baseUrl` in one file and `baseUrl` in another are what make the collection portable. - **The collection file declares nothing about which keys an environment must supply.** Its own top-level fields are `info`, `item`, `event`, `variable`, `auth` and `protocolProfileBehavior`; none of them is a list of required environment keys. ## What this buys and what it quietly costs The separation is a genuine win and a genuine liability at the same time: 1. **Portability, at the price of self-sufficiency.** The collection runs anywhere, but the collection *alone* runs nowhere useful — someone must supply the matching value file. 2. **Independent versioning, at the price of drift.** The two documents are edited on different days by different people. A `key` added to the file you use every day is not automatically in the file nobody has opened for a month. 3. **Late discovery.** Because no part of the collection declares the keys it needs, a missing entry is not a load-time error. It surfaces when that particular request is sent against that particular environment. ## Reading one in practice Opening the file is the fastest way to answer most environment questions: the `values` array is readable JSON, one object per variable, and `disabled` entries are visible right there next to the live ones. Because the file is plain JSON with a stable shape, it diffs cleanly in review — an added `key` or a changed `value` shows up as a one-line change, which is the strongest argument for keeping these files where the rest of the team can see them rather than only on one machine.

  • If you export the collection and send it to a colleague, do they get the environment too?
    No. The environment is a separate document, so exporting the collection hands over requests with nothing behind them. The colleague needs the environment file as well, or values of their own for the same keys. This is the standard cause of a collection that runs for its author and fails immediately for everyone else.
  • Can two environment files define the same key with different values?
    Yes, and that is the whole point of the arrangement. `baseUrl` in one file and `baseUrl` in another are what let one unchanged collection be run against different deployments. The collection never mentions either value; it names the key, and the file the run was pointed at supplies the value.

saying these in an interview costs you the question

  • Says the environment's values are stored inside the collection file
  • Thinks exporting a collection also exports its environment values
  • Believes a run can be pointed at several environment files at once
  • Assumes every environment file defines the same set of keys
  • Treats a disabled entry as one that was deleted from the file