Environments

Learn how to manage feature flags across different environments in your application.

Managing Environments

Environments in MyFlags allow you to manage feature flags differently across your development, staging, and production environments. This ensures safe testing and controlled rollouts.

Default Environments

MyFlags comes with three default environments:

Development

For local development and testing

Staging

For pre-production testing and validation

Production

For your live application

Environment Configuration

Each environment can be configured with:

  • Unique API keys for secure access
  • Different feature flag values
  • Environment-specific targeting rules
  • Custom environment variables

Using Environments in Code

Here's how to initialize the SDK with different environments:

// Initialize with development environment
import { MyFlagsSDK } from "@myflags/core";

const sdk = new MyFlagsSDK({
  apiKey: 'dev-api-key',
  projectId: 'your-project-id',
  environment: 'development'
});

// Initialize with production environment
const sdk = new MyFlagsSDK({
  apiKey: 'prod-api-key',
  projectId: 'your-project-id',
  environment: 'production'
});

The environment setting ensures you're using the correct feature flag values for your current environment.

Best Practices

  • Use different API keys for each environment
  • Keep production feature flags conservative
  • Test feature flags thoroughly in staging
  • Use environment variables for configuration
  • Regularly clean up unused feature flags