/cursor-tutorials

How to make Cursor respect dev and prod environments

Learn how to configure Cursor to properly handle dev and prod environments and keep your workflows clean and consistent.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to make Cursor respect dev and prod environments

Cursor respects dev and prod environments the same way any local editor does: it follows whatever environment variables, config files, and run scripts you set up on your machine. Cursor itself does not manage environments for you — but you can make Cursor reliably use and respect your dev/prod setup by structuring your project correctly, using environment variables, and guiding Cursor in prompts to stick to the right environment file when making changes. The key is to make your environment boundaries explicit in your codebase so Cursor can reason about them without guessing.

 

What “making Cursor respect dev and prod environments” really means

 

Because Cursor runs on your local machine and uses your Node/Python/whatever runtimes, the way to make it reliably handle different environments is:

  • Use real environment files like .env, .env.development, .env.production.
  • Use real environment switching in your package.json scripts, backend config, or Python settings.
  • Tell Cursor, in your instructions, which environment file it should touch so it does not modify the wrong one.
  • Use a consistent pattern for loading environment variables so Cursor recognizes it in future edits.
  • Use the integrated terminal to run the app exactly the same way you would outside Cursor.

Cursor follows your patterns. If your environment setup is clean, Cursor respects it automatically.

 

The practical setup (Node.js example)

 

This is the most common pattern in real-world Node applications. It works perfectly inside Cursor.

  • Create environment files:
// Development environment variables
echo "API_URL=http://localhost:3000" > .env.development

// Production environment variables
echo "API_URL=https://api.yoursite.com" > .env.production
  • Install dotenv (if not already):
npm install dotenv
  • Load the correct file depending on NODE\_ENV:
// config/env.js
import dotenv from "dotenv";
import { existsSync } from "fs";

const envFile = `.env.${process.env.NODE_ENV || "development"}`;

if (existsSync(envFile)) {
  dotenv.config({ path: envFile });
} else {
  dotenv.config(); // fallback to .env
}

export default process.env;
  • Use scripts that explicitly set the environment:
{
  "scripts": {
    "dev": "NODE_ENV=development node server.js",
    "prod": "NODE_ENV=production node server.js"
  }
}

Now Cursor will automatically understand:

  • dev commands use .env.development
  • prod commands use .env.production

Because these files are named clearly and the script logic is explicit, Cursor will not confuse them.

 

Python example (flask/django style)

 

The same principle works in Python:

  • Create .env.development and .env.production
  • Use python-dotenv
from dotenv import load_dotenv
import os

env = os.getenv("APP_ENV", "development")
env_file = f".env.{env}"

load_dotenv(env_file)
  • Run your app with explicit environment:
APP_ENV=development flask run
APP_ENV=production flask run

Cursor will follow whatever rules you define.

 

How to make Cursor “behave” when editing environment‑specific code

 

Cursor sometimes “forgets” which environment you’re using unless you tell it. The fix is simple: include a short instruction that becomes part of your project notes or your per-edit prompt.

For example, when editing dev-only code, tell Cursor:

// Instruction for Cursor:
// When modifying environment variables, use .env.development only.
// Do not touch .env.production.

This prevents accidental overwrites. Cursor respects clear boundaries.

 

Best practices to avoid Cursor hallucinations with environments

 

  • Keep environment logic in one file like config/env.js or settings/env.py so Cursor has a single source of truth.
  • Never mix dev and prod logic in the same file. Cursor will follow your structure.
  • Store secrets only in .env files, not in code. Cursor will not try to inline them.
  • Use consistent names (.env.development, not .env.dev sometimes and .dev.env other times).
  • Run the app with correct scripts in Cursor’s terminal so it loads the right environment.

 

How Cursor actually uses the environment when running code

 

This is often misunderstood. Cursor:

  • uses your local machine’s Node/Python installations
  • uses your OS environment variables
  • does not “change environments” automatically — your scripts do
  • does not run code on a server — everything is local

This is why good environment setup matters: Cursor isn’t doing anything magical. It's just following your system.

 

Final summary (simple version)

 

  • Create separate .env.development and .env.production files.
  • Load them with code that chooses based on NODE_ENV or APP_ENV.
  • Use run scripts that explicitly set NODE\_ENV (or your variable).
  • Tell Cursor which environment file it should modify when making edits.
  • Keep environment logic organized and consistent so Cursor can reason cleanly.

If your project is structured cleanly, Cursor will respect dev and prod automatically, reliably, and safely.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022