Skip to Content
API ReferenceEnvironment Config

Environment Config

RNCopilot centralizes all environment configuration in a single typed module. The app boots and works without any environment variables configured — all external services degrade gracefully.

Source: src/config/env.ts

Usage

import { env } from '@/config/env'; console.log(env.apiBaseUrl); // 'https://api.example.com' console.log(env.isDev); // true (in development) console.log(env.supabaseUrl); // '' (if not configured)

env Object

PropertyTypeDefaultDescription
supabaseUrlstring''Supabase project URL
supabaseAnonKeystring''Supabase anonymous/public key
apiBaseUrlstring'https://api.example.com'Base URL for the API client
sentryDsnstring''Sentry DSN for error tracking
appEnv'development' | 'staging' | 'production''development'Current app environment
isDevbooleancomputedtrue when appEnv === 'development'
isProdbooleancomputedtrue when appEnv === 'production'

Environment Variables

All environment variables use the EXPO_PUBLIC_ prefix, which makes them available at runtime in Expo:

VariableMaps To
EXPO_PUBLIC_SUPABASE_URLenv.supabaseUrl
EXPO_PUBLIC_SUPABASE_PUBLISHED_KEYenv.supabaseAnonKey
EXPO_PUBLIC_API_BASE_URLenv.apiBaseUrl
EXPO_PUBLIC_SENTRY_DSNenv.sentryDsn
EXPO_PUBLIC_APP_ENVenv.appEnv

Variables are read from process.env first, then from expo-constants (Constants.expoConfig.extra), with a fallback to the default value.

.env File

Copy the example file and fill in values as needed:

cp .env.example .env
# .env EXPO_PUBLIC_SUPABASE_URL=https://your-project.supabase.co EXPO_PUBLIC_SUPABASE_PUBLISHED_KEY=your-anon-key EXPO_PUBLIC_API_BASE_URL=https://api.your-app.com EXPO_PUBLIC_SENTRY_DSN=https://your-dsn@sentry.io/123 EXPO_PUBLIC_APP_ENV=development

The .env file is gitignored. Each developer maintains their own local copy. The .env.example file is committed and documents all available variables.

Graceful Degradation

The app is designed to work without any environment variables configured:

  • Supabase — If supabaseUrl or supabaseAnonKey is empty, the Supabase client initializes gracefully and auth features are disabled. The app boots normally.
  • API base URL — Falls back to https://api.example.com. Replace this when connecting to your real backend.
  • Sentry — If sentryDsn is empty, error reporting is silently disabled.

Never commit real credentials to version control. The .env file is in .gitignore by default.

validateEnv

A utility function that checks for missing critical variables and returns warnings:

import { validateEnv } from '@/config/env'; const warnings = validateEnv(); // ['EXPO_PUBLIC_SUPABASE_URL is not set', 'EXPO_PUBLIC_SUPABASE_PUBLISHED_KEY is not set']

This is useful during app initialization to log warnings in development without crashing in production.

Last updated on