{
  "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": "e6988a974973e9090ce70406c38cb2b9e0eac9fa",
    "updated_at": "2026-05-15T15:50:22.536Z",
    "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
      }
    ]
  },
  "chunks": [
    {
      "id": "api/cypress-api/env#syntax",
      "doc_id": "api/cypress-api/env",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\nCypress.env()Cypress.env(name)Cypress.env(name, value)Cypress.env(object)\n```\n\n### Arguments\n\n**name _(String)_**\n\nThe name of the environment variable to get or set.\n\n**value _(String)_**\n\nThe value of the environment variable to set.\n\n**object _(Object)_**\n\nSet multiple environment variables with an object literal.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 53
    },
    {
      "id": "api/cypress-api/env#arguments",
      "doc_id": "api/cypress-api/env",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**name _(String)_**\n\nThe name of the environment variable to get or set.\n\n**value _(String)_**\n\nThe value of the environment variable to set.\n\n**object _(Object)_**\n\nSet multiple environment variables with an object literal.\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 45
    },
    {
      "id": "api/cypress-api/env#examples",
      "doc_id": "api/cypress-api/env",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Arguments\n\n#### Get all environment variables from the Cypress configuration\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env() // => {apiUrl: 'https://api.example.com', apiVersion: 'v1'}\n```\n\n### Name\n\n#### Return a single environment variable from the Cypress configuration\n\n**Boolean**\n\nWe automatically normalize both the key and the value when passed via the command line. Cypress will automatically convert values into Number or Boolean.\n\n```\nCYPRESS_HOST=laura.dev CYPRESS_IS_CI=true CYPRESS_API_VERSION=123 cypress run\n```\n\n```\nCypress.env('HOST') // => \"laura.dev\"Cypress.env('IS_CI') // => trueCypress.env('API_VERSION') // => 123\n```\n\n### Name and Value\n\n#### Change environment variables from the Cypress configuration from within your tests\n\n**Scope**\n\nRemember, 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._\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nCypress.env('host', 'http://server.dev.local')Cypress.env('host') // => http://server.dev.local\n```\n\n### Object\n\n#### Override multiple values from the Cypress configuration by passing an object\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env({  host: 'http://server.dev.local',  apiVersion: 'v2',})Cypress.env() // => {apiVersion: 'v2', host: 'http://server.dev.local'}\n```\n\n### From a plugin\n\nHere's an example that uses `Cypress.env` to access an environment variable that's been [dynamically set in a plugin](/llm/markdown/app/plugins/plugins-guide.md).\n\nUse this approach to grab the value of an environment variable _once_ before any of the tests in your spec run.\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { 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    },  },})\n```\n\n```\nimport { 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    },  },})\n```\n\n```\n// 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)    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 580
    },
    {
      "id": "api/cypress-api/env#no-arguments",
      "doc_id": "api/cypress-api/env",
      "heading": "No Arguments",
      "heading_level": 3,
      "content_markdown": "### No Arguments\n\n#### Get all environment variables from the Cypress configuration\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env() // => {apiUrl: 'https://api.example.com', apiVersion: 'v1'}\n```\n",
      "section": "api",
      "anchors": [
        "no-arguments"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 79
    },
    {
      "id": "api/cypress-api/env#get-all-environment-variables-from-the-cypress-configuration",
      "doc_id": "api/cypress-api/env",
      "heading": "Get all environment variables from the Cypress configuration",
      "heading_level": 4,
      "content_markdown": "#### Get all environment variables from the Cypress configuration\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    apiUrl: 'https://api.example.com',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env() // => {apiUrl: 'https://api.example.com', apiVersion: 'v1'}\n```\n",
      "section": "api",
      "anchors": [
        "get-all-environment-variables-from-the-cypress-configuration"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 75
    },
    {
      "id": "api/cypress-api/env#name",
      "doc_id": "api/cypress-api/env",
      "heading": "Name",
      "heading_level": 3,
      "content_markdown": "### Name\n\n#### Return a single environment variable from the Cypress configuration\n\n**Boolean**\n\nWe automatically normalize both the key and the value when passed via the command line. Cypress will automatically convert values into Number or Boolean.\n\n```\nCYPRESS_HOST=laura.dev CYPRESS_IS_CI=true CYPRESS_API_VERSION=123 cypress run\n```\n\n```\nCypress.env('HOST') // => \"laura.dev\"Cypress.env('IS_CI') // => trueCypress.env('API_VERSION') // => 123\n```\n",
      "section": "api",
      "anchors": [
        "name"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 75
    },
    {
      "id": "api/cypress-api/env#return-a-single-environment-variable-from-the-cypress-configuration",
      "doc_id": "api/cypress-api/env",
      "heading": "Return a single environment variable from the Cypress configuration",
      "heading_level": 4,
      "content_markdown": "#### Return a single environment variable from the Cypress configuration\n\n**Boolean**\n\nWe automatically normalize both the key and the value when passed via the command line. Cypress will automatically convert values into Number or Boolean.\n\n```\nCYPRESS_HOST=laura.dev CYPRESS_IS_CI=true CYPRESS_API_VERSION=123 cypress run\n```\n\n```\nCypress.env('HOST') // => \"laura.dev\"Cypress.env('IS_CI') // => trueCypress.env('API_VERSION') // => 123\n```\n",
      "section": "api",
      "anchors": [
        "return-a-single-environment-variable-from-the-cypress-configuration"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 72
    },
    {
      "id": "api/cypress-api/env#name-and-value",
      "doc_id": "api/cypress-api/env",
      "heading": "Name and Value",
      "heading_level": 3,
      "content_markdown": "### Name and Value\n\n#### Change environment variables from the Cypress configuration from within your tests\n\n**Scope**\n\nRemember, 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._\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nCypress.env('host', 'http://server.dev.local')Cypress.env('host') // => http://server.dev.local\n```\n",
      "section": "api",
      "anchors": [
        "name-and-value"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 115
    },
    {
      "id": "api/cypress-api/env#change-environment-variables-from-the-cypress-configuration-from-within-your-tests",
      "doc_id": "api/cypress-api/env",
      "heading": "Change environment variables from the Cypress configuration from within your tests",
      "heading_level": 4,
      "content_markdown": "#### Change environment variables from the Cypress configuration from within your tests\n\n**Scope**\n\nRemember, 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._\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',  },})\n```\n\n```\nCypress.env('host', 'http://server.dev.local')Cypress.env('host') // => http://server.dev.local\n```\n",
      "section": "api",
      "anchors": [
        "change-environment-variables-from-the-cypress-configuration-from-within-your-tests"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 109
    },
    {
      "id": "api/cypress-api/env#object",
      "doc_id": "api/cypress-api/env",
      "heading": "Object",
      "heading_level": 3,
      "content_markdown": "### Object\n\n#### Override multiple values from the Cypress configuration by passing an object\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env({  host: 'http://server.dev.local',  apiVersion: 'v2',})Cypress.env() // => {apiVersion: 'v2', host: 'http://server.dev.local'}\n```\n",
      "section": "api",
      "anchors": [
        "object"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 87
    },
    {
      "id": "api/cypress-api/env#override-multiple-values-from-the-cypress-configuration-by-passing-an-object",
      "doc_id": "api/cypress-api/env",
      "heading": "Override multiple values from the Cypress configuration by passing an object",
      "heading_level": 4,
      "content_markdown": "#### Override multiple values from the Cypress configuration by passing an object\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  env: {    host: 'laura.dev',    apiVersion: 'v1',  },})\n```\n\n```\nCypress.env({  host: 'http://server.dev.local',  apiVersion: 'v2',})Cypress.env() // => {apiVersion: 'v2', host: 'http://server.dev.local'}\n```\n",
      "section": "api",
      "anchors": [
        "override-multiple-values-from-the-cypress-configuration-by-passing-an-object"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 84
    },
    {
      "id": "api/cypress-api/env#from-a-plugin",
      "doc_id": "api/cypress-api/env",
      "heading": "From a plugin",
      "heading_level": 3,
      "content_markdown": "### From a plugin\n\nHere's an example that uses `Cypress.env` to access an environment variable that's been [dynamically set in a plugin](/llm/markdown/app/plugins/plugins-guide.md).\n\nUse this approach to grab the value of an environment variable _once_ before any of the tests in your spec run.\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { 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    },  },})\n```\n\n```\nimport { 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    },  },})\n```\n\n```\n// 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)    })  })})\n```\n",
      "section": "api",
      "anchors": [
        "from-a-plugin"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 223
    },
    {
      "id": "api/cypress-api/env#notes",
      "doc_id": "api/cypress-api/env",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Why would I ever need to use environment variables?\n\nThe [Environment Variables & Secrets](/llm/markdown/app/guides/environment-variables.md) guide explains common use cases.\n\n### Can I pass in environment variables from the command line?\n\nYes. You can do that and much more.\n\nThe [Environment Variables & Secrets](/llm/markdown/app/guides/environment-variables.md) guide explains the other ways you can set environment variables for your tests.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 79
    },
    {
      "id": "api/cypress-api/env#can-i-pass-in-environment-variables-from-the-command-line",
      "doc_id": "api/cypress-api/env",
      "heading": "Can I pass in environment variables from the command line?",
      "heading_level": 3,
      "content_markdown": "### Can I pass in environment variables from the command line?\n\nYes. You can do that and much more.\n\nThe [Environment Variables & Secrets](/llm/markdown/app/guides/environment-variables.md) guide explains the other ways you can set environment variables for your tests.\n",
      "section": "api",
      "anchors": [
        "can-i-pass-in-environment-variables-from-the-command-line"
      ],
      "path": "/llm/json/chunked/api/cypress-api/env.json",
      "token_estimate": 49
    }
  ]
}