TL;DR
These prompts help you properly set up environment variables in your project. They create .env files, configure your framework correctly, add validation, and ensure secrets never get committed to git. The prompts cover Next.js, Node.js, Python, and deployment platforms.
Complete Environment Variable Setup
Use this prompt to set up a proper environment variable system from scratch:
Set up a complete environment variable system for this project.
Create:
- .env.example with all required variables and placeholder values
- A typed config module that loads and validates env vars at startup
- Clear error messages when required variables are missing
- Separation between public (client-safe) and private (server-only) variables
Requirements:
- Fail fast: app should not start if required env vars are missing
- Type safety: config values should be typed, not just strings
- Documentation: comments explaining what each variable is for
- Defaults: sensible defaults for non-sensitive variables
Also ensure:
- .env is in .gitignore
- .env.local is in .gitignore
- Only .env.example is committed
Framework-Specific Setup
Next.js
Set up environment variables properly for my Next.js project.
Create:
- .env.local.example with all variables
- A lib/env.ts file that exports validated, typed env vars
- Proper separation of NEXT_PUBLIC_ vars vs server-only vars
Rules:
- NEXT_PUBLIC_ prefix only for variables that MUST be in the browser
- Secret keys, API keys, database URLs must NOT have NEXT_PUBLIC_
- Validate at build time, not runtime
- Use zod or similar for validation
The config should work with both Pages Router and App Router.
Show me which variables are safe for client-side and which must stay server-only.
Node.js with TypeScript
Create a type-safe environment variable configuration for my Node.js TypeScript project.
Requirements:
- Use dotenv to load .env files
- Create a config.ts that validates and exports typed env vars
- Use zod for validation with clear error messages
- Support different environments (development, production, test)
- Throw at startup if required vars are missing
Structure:
- config/index.ts (main config export)
- config/schema.ts (zod schema)
- .env.example (template with all vars)
Include:
- DATABASE_URL
- API keys (typed as string, validated as non-empty)
- PORT (with default)
- NODE_ENV (enum: development, production, test)
Python with Pydantic
Set up environment variable management for my Python project using Pydantic.
Create:
- config.py with a Settings class using pydantic-settings
- Proper .env file loading
- Type hints and validation for all settings
- Support for different environments
The Settings class should:
- Load from .env file automatically
- Validate types (strings, integers, booleans)
- Have clear field descriptions
- Raise validation errors with helpful messages
- Support nested settings if needed
Also create .env.example with all required variables documented.
Deployment Platform Setup
Vercel
Help me set up environment variables for Vercel deployment.
I need:
- List of all env vars my app needs
- Which ones should be marked as "Sensitive" in Vercel
- Which ones need different values for Preview vs Production
- How to reference them in my code
Also create a vercel.json if needed for any special env var configuration.
Format the output as a checklist I can follow in the Vercel dashboard, with the variable name, which environments it applies to, and whether it's sensitive.
Railway / Render
Set up environment variables for Railway (or Render) deployment.
Create:
- A railway.toml or render.yaml with env var references
- List of all required env vars I need to set in the dashboard
- Documentation for each variable's purpose
- Any service-specific variables (like PORT for Railway)
Include platform-specific considerations:
- Railway provides PORT automatically
- Database URLs from Railway's built-in databases
- Proper health check configuration
Never commit .env files: Even .env files with "fake" values can reveal your variable naming scheme and expected configuration. Always use .env.example with clearly placeholder values instead.
Migration from Hardcoded Values
I have hardcoded configuration values throughout my codebase. Help me migrate them to environment variables.
For each hardcoded value found:
- Create an appropriately named env var
- Update the code to read from env var
- Add to .env.example with a placeholder
- Add to the config validation
Look for:
- URLs (API endpoints, webhooks)
- Credentials and keys
- Feature flags
- Configuration values (timeouts, limits)
- Third-party service IDs
Group related variables and use consistent naming:
- DATABASE_URL, DATABASE_POOL_SIZE
- STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET
- FEATURE_NEW_DASHBOARD, FEATURE_BETA_ACCESS
Pro tip: Use a consistent naming convention like SERVICE_VARIABLE_NAME. For example: STRIPE_SECRET_KEY, SUPABASE_URL, OPENAI_API_KEY. This makes it easy to find and manage related variables.
What's the difference between .env and .env.local?
.env is typically committed to git with placeholder or default values. .env.local contains your actual secrets and should never be committed. Most frameworks load .env.local with higher priority.
Should I use NEXT_PUBLIC_ prefix for all environment variables?
No. Only use NEXT_PUBLIC_ for variables that must be accessible in the browser. Secret keys, database credentials, and API keys should never have this prefix as they would be exposed to users.
How do I set environment variables in production?
Use your hosting platform's environment variable settings. Vercel, Netlify, Railway, and other platforms have dashboards or CLI commands to set production environment variables securely.
Verify Your Env Setup
Scan your repository to check for exposed secrets and missing .gitignore entries.
Start Free Scan