Collection-level defaults vs environment variables for BASE_URL in Postman: which ensures consistent local and production runs?
0 reputation · 07 Apr 2025, 08:47 UTC
The goal is to configure a Postman collection so that the BASE_URL variable resolves to http://localhost:3000 when run locally and to the production host when run against a production endpoint, without requiring the user to manually select a different environment each time.
The challenge arises because collection‑level variables that include a default value are used when no environment is explicitly chosen, which can override an environment‑specific BASE_URL. Postman Monitor and the CLI inherit the workspace’s default environment, which may lack a production BASE_URL, leading to undefined variable errors. Using pm.globals makes the variable available everywhere but does not persist between Monitor runs, causing inconsistency.
- Which variable scope—collection‑level with a default value or environment‑only—provides reliable BASE_URL resolution across Collection Runner, Newman, and Postman Monitor?
- Does defining BASE_URL as a collection variable with a default value and then overriding it via an environment produce unexpected behavior in any of these runners?