October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Configure Cypress with the Configuration File

A practical guide to Cypress project configuration: choose the right config file syntax, place E2E and Component Testing options correctly, and manage overrides and secrets.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure Cypress in a project-level cypress.config.js or cypress.config.ts file. Put settings shared across test types at the top level, E2E settings under e2e, and Component Testing settings under component. Use defineConfig() for editor completion, and reserve setupNodeEvents for Node-side event handlers or configuration logic.

Create the Cypress configuration file

At the project root, create or edit cypress.config.js for JavaScript or cypress.config.ts for TypeScript. Cypress supports CommonJS and ESM syntax. Match the syntax to your Node project’s module settings.

As an Amazon Associate I earn from qualifying purchases.

CommonJS JavaScript

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:8080',
  },
})

TypeScript or ESM

import { defineConfig } from 'cypress'

export default defineConfig({
  e2e: {
    baseUrl: 'http://localhost:8080',
  },
})

Replace the illustrative localhost address with the address where your application runs. Cypress recommends defineConfig() because it enables automatic code completion in many editors; it is not required for Cypress to parse the configuration. See Cypress’s configuration reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the project uses "type": "module" but you need a CommonJS config, use a .cjs extension. For an ESM config in a CommonJS project, use .mjs or set the package type to module. See the Cypress configuration reference for syntax and file details.

Put each setting at the right level

Top-level options apply generally; test-type blocks hold options specific to their runner. For example, baseUrl and specPattern are E2E options, while Component Testing uses options such as devServer and indexHtmlFile.

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  defaultCommandTimeout: 5000,
  e2e: {
    baseUrl: 'http://localhost:8080',
    setupNodeEvents(on, config) {
      // Register Node-side event handlers here.
      return config
    },
  },
  component: {
    // Component Testing options belong here.
  },
})

This shows the configuration’s shape; select supported options and defaults from the live configuration reference. Defaults can vary by Cypress version. The reference currently documents values including baseUrl: null, an E2E specPattern of cypress/e2e/**/*.cy.{js,jsx,ts,tsx}, and testIsolation: true; check the reference for the version installed in your project.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Use baseUrl for your application

Set e2e.baseUrl when tests should use relative URLs. Cypress prefixes it to URLs passed to cy.visit() and cy.request(). For example, after setting the base URL, a test can call cy.visit('/login') rather than repeating the host. The E2E guide explains the setting at Effective E2E testing in Cypress.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose how to override configuration

Use the narrowest mechanism that fits the setting’s scope. Keep stable project behavior in the checked-in config; use command-line or environment-specific overrides when a run or machine needs different values.

Mechanism Use it for Example
Top-level config Shared settings across testing types defaultCommandTimeout
e2e or component Settings belonging to that test runner e2e.baseUrl; Component Testing’s devServer
--config Override individual configuration values for a run cypress run --config viewportWidth=1280,viewportHeight=720
--config-file Select a different configuration file cypress run --config-file tests/cypress.config.js
Environment variables Supply machine- or CI-specific settings without editing project config CYPRESS_VIEWPORT_WIDTH and CYPRESS_VIEWPORT_HEIGHT
Runtime test overrides Settings needed only for a particular test or suite Use the runtime override mechanism documented for the relevant setting
setupNodeEvents Register Node event handlers or calculate config dynamically Return the modified config from the function

Refer to the Cypress configuration reference for accepted CLI options and environment variable behavior; names and defaults are configuration-specific.

Set environment values and keep secrets out of source

Cypress can receive environment values from the config’s env property, a cypress.env.json file, CYPRESS_* operating-system variables, the --env CLI option, or setupNodeEvents. For values that differ between local development and CI, choose the source that matches how the value is managed in your project.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

For a secret such as an API key, read it from the process environment instead of writing its literal value into a checked-in config:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    env: {
      apiKey: process.env.API_KEY,
    },
  },
})

Provide API_KEY through your local shell or CI secret settings. Cypress documents environment value sources and access at Environment variables and secrets in Cypress.

Use setupNodeEvents only for Node-side work

setupNodeEvents(on, config) runs in Node, not in the browser where test commands run. Use it to register Node event handlers or make configuration changes that depend on Node access. Return the config object if you modify it so Cypress can apply those values.

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      config.baseUrl = process.env.CYPRESS_BASE_URL || config.baseUrl
      return config
    },
  },
})

Do not call browser-side Cypress or cy commands inside this function. The Configuration API describes the function and its Node-side role.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Update legacy plugin configuration

In older Cypress projects, plugin setup may live in cypress/plugins/index.js. That file is no longer automatically loaded; move the relevant Node event registration into setupNodeEvents in the configuration file. Consult the Cypress migration guide for changes specific to the version you are upgrading from. For Component Testing, configure the supported devServer in the component block rather than carrying forward an obsolete setup pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify changes and troubleshoot common problems

The config file is not being applied

  • Confirm the file is in the project location Cypress is using and that its name and extension match the chosen JavaScript or TypeScript module format.
  • If the file is elsewhere or has another name, specify it with cypress run --config-file path/to/cypress.config.js.
  • Check for mismatched module syntax: CommonJS uses require and module.exports; ESM uses import and export default. Use .cjs or .mjs when needed to resolve the project’s module-type mismatch.

Relative visits or requests target the wrong host

  • Set the application host under e2e.baseUrl, not at the shared top level.
  • Check whether --config or a CYPRESS_* variable is overriding the value for this run.
  • Make sure the app is available at the configured address before running tests.

An environment value is missing

  • Check the spelling and source: config env, cypress.env.json, OS variables, --env, and setupNodeEvents are distinct inputs.
  • For a secret read through process.env, confirm the variable is actually set in the shell or CI job that starts Cypress.

Node event logic does not behave as expected

  • Put it in the correct test-type block’s setupNodeEvents.
  • Keep browser-only Cypress and cy commands out of the Node function.
  • Return the config object after changing it.

When you edit the configuration while Cypress is open, Cypress automatically restarts after detecting the change and closes open browsers. This is expected behavior documented in Effective E2E testing in Cypress.

Or skip the browser setup

If your goal is to capture a website rather than configure Cypress for browser testing, ScreenshotNeo offers a one-request screenshot API and an MCP server. A GET request takes a URL and returns a PNG, JPEG, WebP, or PDF. Its default cleanup accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with the result identified in response headers. AI agents can use its MCP tools to take screenshots, inspect page information, and capture PDFs. Free includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots.

Example request, using the documented cURL form:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options, and ScreenshotNeo for the service. Sign up for 1,000 free screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.