{
  "doc": {
    "id": "api/cypress-api/env",
    "title": "Cypress.env | Cypress Documentation",
    "description": "Deprecated: Get and set Cypress environment variables in your tests",
    "section": "api",
    "source_path": "/llm/markdown/api/cypress-api/env.md",
    "version": "6a908a532b1fca4ed18538a4c1c5a9bc7f24f403",
    "updated_at": "2026-05-01T19:25:18.656Z",
    "headings": [
      {
        "id": "api/cypress-api/env#cypress-env-cypress-documentation",
        "text": "Cypress.env | Cypress Documentation",
        "level": 1
      },
      {
        "id": "api/cypress-api/env#cypress-env",
        "text": "Cypress.env",
        "level": 1
      },
      {
        "id": "api/cypress-api/env#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/cypress-api/env#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/cypress-api/env#no-arguments",
        "text": "No Arguments",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#get-all-environment-variables-from-the-cypress-configuration",
        "text": "Get all environment variables from the Cypress configuration",
        "level": 4
      },
      {
        "id": "api/cypress-api/env#name",
        "text": "Name",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#return-a-single-environment-variable-from-the-cypress-configuration",
        "text": "Return a single environment variable from the Cypress configuration",
        "level": 4
      },
      {
        "id": "api/cypress-api/env#name-and-value",
        "text": "Name and Value",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#change-environment-variables-from-the-cypress-configuration-from-within-your-tests",
        "text": "Change environment variables from the Cypress configuration from within your tests",
        "level": 4
      },
      {
        "id": "api/cypress-api/env#object",
        "text": "Object",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#override-multiple-values-from-the-cypress-configuration-by-passing-an-object",
        "text": "Override multiple values from the Cypress configuration by passing an object",
        "level": 4
      },
      {
        "id": "api/cypress-api/env#from-a-plugin",
        "text": "From a plugin",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/cypress-api/env#why-would-i-ever-need-to-use-environment-variables",
        "text": "Why would I ever need to use environment variables?",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#can-i-pass-in-environment-variables-from-the-command-line",
        "text": "Can I pass in environment variables from the command line?",
        "level": 3
      },
      {
        "id": "api/cypress-api/env#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/cypress-api/env#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "Cypress.env | Cypress Documentation"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Deprecated"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`Cypress.env()` was deprecated in Cypress `15.10.0` and will be removed in a future major version."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress recommends migrating to use "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/env.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.env()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " or "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/cypress-api/expose.md",
            "children": [
              {
                "type": "text",
                "value": "`Cypress.expose()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " instead."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Please see the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/migration-guide.md#Migrating-away-from-Cypressenv",
            "children": [
              {
                "type": "text",
                "value": "Migration Guide"
              }
            ]
          },
          {
            "type": "text",
            "value": " for more information."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "Cypress.env"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`get` and `set` environment variables in your tests."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Scope"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Environment variables set using `Cypress.env` are only in scope for the current spec file."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress runs each spec file in isolation: the browser is exited between specs. Environment variables added or changed in one spec won't be visible in other specs."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.env()Cypress.env(name)Cypress.env(name, value)Cypress.env(object)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "name (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The name of the environment variable to get or set."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "value (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The value of the environment variable to set."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "object (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Set multiple environment variables with an object literal."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "No Arguments"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get all environment variables from the Cypress configuration"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.js"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.ts"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "const { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "import { defineConfig } from 'cypress'export default defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.env() // => {apiUrl: 'https://api.example.com', apiVersion: 'v1'}"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Name"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Return a single environment variable from the Cypress configuration"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Boolean"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "We automatically normalize both the key and the value when passed via the command line. Cypress will automatically convert values into Number or Boolean."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "CYPRESS_HOST=laura.dev CYPRESS_IS_CI=true CYPRESS_API_VERSION=123 cypress run"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.env('HOST') // => \"laura.dev\"Cypress.env('IS_CI') // => trueCypress.env('API_VERSION') // => 123"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Name and Value"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Change environment variables from the Cypress configuration from within your tests"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Scope"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Remember, any changes that you make to environment variables using this API will only be in effect for the remainder of the tests in the same spec file."
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.js"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.ts"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "const { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "import { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.env('host', 'http://server.dev.local')Cypress.env('host') // => http://server.dev.local"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Object"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Override multiple values from the Cypress configuration by passing an object"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.js"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.ts"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "const { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "import { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.env({  host: 'http://server.dev.local',  apiVersion: 'v2',})Cypress.env() // => {apiVersion: 'v2', host: 'http://server.dev.local'}"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "From a plugin"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Here's an example that uses `Cypress.env` to access an environment variable that's been "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/plugins/plugins-guide.md",
            "children": [
              {
                "type": "text",
                "value": "dynamically set in a plugin"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Use this approach to grab the value of an environment variable once before any of the tests in your spec run."
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.js"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "cypress.config.ts"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "const { defineConfig } = require('cypress')module.exports = defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      config.env.apiBaseUrl =        process.env.NODE_ENV === 'qa'          ? 'https://api-qa.example.com'          : 'https://api.example.com'      return config    },  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "import { defineConfig } from 'cypress'export default defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      config.env.apiBaseUrl =        process.env.NODE_ENV === 'qa'          ? 'https://api-qa.example.com'          : 'https://api.example.com'      return config    },  },})"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// cypress/e2e/api-tests.cy.jsdescribe('API tests', () => {  let apiBaseUrl  before(() => {    apiBaseUrl = Cypress.env('apiBaseUrl')  })  it('can make requests to the correct environment', () => {    cy.request({      method: 'GET',      url: `${apiBaseUrl}/users`,    }).then((response) => {      expect(response.status).to.eq(200)    })  })})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Why would I ever need to use environment variables?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/guides/environment-variables.md",
            "children": [
              {
                "type": "text",
                "value": "Environment Variables & Secrets"
              }
            ]
          },
          {
            "type": "text",
            "value": " guide explains common use cases."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Can I pass in environment variables from the command line?"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Yes. You can do that and much more."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/guides/environment-variables.md",
            "children": [
              {
                "type": "text",
                "value": "Environment Variables & Secrets"
              }
            ]
          },
          {
            "type": "text",
            "value": " guide explains the other ways you can set environment variables for your tests."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#15-10-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "15.10.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`Cypress.env()` API deprecated"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "The "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/guides/environment-variables.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Environment Variables & Secrets"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " guide"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Cypress configuration"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/env.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.env()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/cypress-api/expose.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Cypress.expose()"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/migration-guide.md#Migrating-away-from-Cypressenv",
                    "children": [
                      {
                        "type": "text",
                        "value": "Migration Guide to `cy.env()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 887
}