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

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
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.
Because Cursor runs on your local machine and uses your Node/Python/whatever runtimes, the way to make it reliably handle different environments is:
Cursor follows your patterns. If your environment setup is clean, Cursor respects it automatically.
This is the most common pattern in real-world Node applications. It works perfectly inside Cursor.
// Development environment variables
echo "API_URL=http://localhost:3000" > .env.development
// Production environment variables
echo "API_URL=https://api.yoursite.com" > .env.production
npm install dotenv
// 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;
{
"scripts": {
"dev": "NODE_ENV=development node server.js",
"prod": "NODE_ENV=production node server.js"
}
}
Now Cursor will automatically understand:
Because these files are named clearly and the script logic is explicit, Cursor will not confuse them.
The same principle works in Python:
from dotenv import load_dotenv
import os
env = os.getenv("APP_ENV", "development")
env_file = f".env.{env}"
load_dotenv(env_file)
APP_ENV=development flask run
APP_ENV=production flask run
Cursor will follow whatever rules you define.
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.
This is often misunderstood. Cursor:
This is why good environment setup matters: Cursor isn’t doing anything magical. It's just following your system.
If your project is structured cleanly, Cursor will respect dev and prod automatically, reliably, and safely.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.