Manage environment variables securely across environments
# Environment Configuration Complete Guide for Google Antigravity
Manage environment variables securely across all environments with Google Antigravity IDE.
## Type-Safe Environment Variables
```typescript
// env.ts
import { z } from "zod";
const envSchema = z.object({
DATABASE_URL: z.string().url(),
REDIS_URL: z.string().url(),
JWT_SECRET: z.string().min(32),
STRIPE_SECRET_KEY: z.string().startsWith("sk_"),
NEXT_PUBLIC_APP_URL: z.string().url(),
NEXT_PUBLIC_SUPABASE_URL: z.string().url(),
NEXT_PUBLIC_SUPABASE_ANON_KEY: z.string(),
NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
PORT: z.coerce.number().default(3000)
});
const parsed = envSchema.safeParse(process.env);
if (!parsed.success) {
console.error("Invalid environment variables:", parsed.error.flatten().fieldErrors);
throw new Error("Invalid environment variables");
}
export const env = parsed.data;
```
## Configuration Module
```typescript
// lib/config.ts
import { env } from "./env";
export const config = {
app: {
name: "My App",
url: env.NEXT_PUBLIC_APP_URL,
env: env.NODE_ENV,
isDev: env.NODE_ENV === "development",
isProd: env.NODE_ENV === "production"
},
database: {
url: env.DATABASE_URL,
poolMin: env.NODE_ENV === "production" ? 5 : 1,
poolMax: env.NODE_ENV === "production" ? 20 : 5
},
auth: {
jwtSecret: env.JWT_SECRET,
tokenExpiry: "7d"
}
} as const;
```
## Best Practices
1. **Validate environment variables** at startup
2. **Use type-safe configuration** with Zod
3. **Never commit secrets** to version control
4. **Use different .env files** per environment
5. **Provide .env.example** for documentation
6. **Rotate secrets regularly** in production
7. **Use secrets manager** for sensitive values
Google Antigravity helps manage environment configuration securely across all environments.This environment prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their environment implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For environment projects, consider mentioning your framework version, coding style, and any specific libraries you're using.