Environments in Postman allow you to store and reuse variables such as base URLs, tokens, and credentials. They help you switch easily between development, testing, staging, and production without modifying requests manually.
Variables inside environments are accessed using the syntax {{variable_name}}. Postman resolves these values dynamically based on the currently selected environment.
// Using an environment variable in a request URL
GET {{base_url}}/users
// Setting an environment variable in Tests tab
pm.environment.set("auth_token", pm.response.json().token);
When the request runs, Postman extracts the token from the response and stores it in the active environment. This token can then be reused in headers or other requests.
Imagine switching between Development and Production environments using the environment dropdown. The same request instantly points to a different server without changes.
// Authorization header using environment variable
Authorization: Bearer {{auth_token}}
base_url