expo-constants
Version: 55.0.5
Provides system information that remains constant throughout the lifetime of your app. Access app configuration, device info, manifest data, and environment constants.
Installation
npx expo install expo-constants
Usage
import Constants from 'expo-constants';
// Get app information
console.log(Constants.expoConfig?.name);
console.log(Constants.expoConfig?.version);
// Get system information
console.log(Constants.systemVersion);
console.log(Constants.platform);
// Get device information
console.log(Constants.deviceName);
console.log(Constants.isDevice);
API Reference
Constants
The Expo configuration object from app.json or app.config.jsconst appName = Constants.expoConfig?.name;
const version = Constants.expoConfig?.version;
const slug = Constants.expoConfig?.slug;
Configuration specific to Expo Go app
The classic manifest object (legacy)
manifest2
ExpoUpdatesManifest | null
The modern manifest format used by expo-updates
appOwnership
'expo' | 'standalone' | 'guest' | null
Indicates the type of app ownership:
expo: Running in Expo Go
standalone: Production build
guest: Guest mode
null: Bare workflow
The human-readable device name (e.g., “John’s iPhone”)
true if running on a physical device, false if simulator/emulator
Platform-specific information:iOS:{
ios: {
platform: string;
model: string;
userInterfaceIdiom: 'phone' | 'tablet' | 'tv';
systemVersion: string;
}
}
Android:{
android: {
versionCode: number;
}
}
The OS version (e.g., “15.0” for iOS, “12” for Android API 31)
The native app version from Info.plist (iOS) or build.gradle (Android)Example: "1.0.0"
The native build numberExample: "42" (iOS) or "42" (Android)
A unique ID for this app session. Changes on each app launch.
Height of the device status bar in pixels
A unique ID for this app installation
Development
true if the app is running in debug mode
The execution environment:
ExecutionEnvironment.Bare: Bare workflow
ExecutionEnvironment.Standalone: Production build
ExecutionEnvironment.StoreClient: Expo Go
System Directories
iOS only: List of system font names available
Examples
Display App Version
import Constants from 'expo-constants';
import { Text, View } from 'react-native';
function AppVersion() {
const version = Constants.expoConfig?.version;
const buildNumber = Constants.nativeBuildVersion;
return (
<View>
<Text>Version: {version}</Text>
<Text>Build: {buildNumber}</Text>
</View>
);
}
Check Environment
import Constants from 'expo-constants';
const isExpoGo = Constants.appOwnership === 'expo';
const isProduction = Constants.appOwnership === 'standalone';
const isBareWorkflow = Constants.appOwnership === null;
if (isExpoGo) {
console.log('Running in Expo Go');
} else if (isProduction) {
console.log('Running production build');
}
app.json:
{
"expo": {
"name": "My App",
"extra": {
"apiUrl": "https://api.example.com",
"apiKey": "abc123"
}
}
}
Usage:
import Constants from 'expo-constants';
const apiUrl = Constants.expoConfig?.extra?.apiUrl;
const apiKey = Constants.expoConfig?.extra?.apiKey;
fetch(`${apiUrl}/data`, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
Environment-Specific Config
app.config.js:
export default {
expo: {
name: 'My App',
extra: {
apiUrl: process.env.API_URL || 'https://api.staging.example.com'
}
}
};
Usage:
import Constants from 'expo-constants';
const API_URL = Constants.expoConfig?.extra?.apiUrl;
Device Detection
import Constants from 'expo-constants';
import { Platform } from 'react-native';
function getDeviceInfo() {
return {
isSimulator: !Constants.isDevice,
deviceName: Constants.deviceName,
osVersion: Constants.systemVersion,
platform: Platform.OS,
appVersion: Constants.expoConfig?.version
};
}
const deviceInfo = getDeviceInfo();
console.log(deviceInfo);
// {
// isSimulator: false,
// deviceName: "John's iPhone",
// osVersion: "17.0",
// platform: "ios",
// appVersion: "1.0.0"
// }
import Constants from 'expo-constants';
import { ScrollView, Text, View, StyleSheet } from 'react-native';
function DebugInfo() {
if (!__DEV__) return null;
return (
<ScrollView style={styles.container}>
<Text style={styles.title}>Debug Information</Text>
<Section title="App">
<Info label="Name" value={Constants.expoConfig?.name} />
<Info label="Version" value={Constants.expoConfig?.version} />
<Info label="Build" value={Constants.nativeBuildVersion} />
<Info label="Session ID" value={Constants.sessionId} />
</Section>
<Section title="Device">
<Info label="Device" value={Constants.deviceName} />
<Info label="Is Device" value={Constants.isDevice} />
<Info label="OS Version" value={Constants.systemVersion} />
</Section>
<Section title="Environment">
<Info label="App Ownership" value={Constants.appOwnership} />
<Info label="Debug Mode" value={Constants.debugMode} />
</Section>
</ScrollView>
);
}
function Section({ title, children }) {
return (
<View style={styles.section}>
<Text style={styles.sectionTitle}>{title}</Text>
{children}
</View>
);
}
function Info({ label, value }) {
return (
<Text style={styles.info}>
{label}: {JSON.stringify(value)}
</Text>
);
}
const styles = StyleSheet.create({
container: { padding: 20 },
title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
section: { marginBottom: 20 },
sectionTitle: { fontSize: 18, fontWeight: '600', marginBottom: 10 },
info: { fontSize: 14, marginBottom: 5 }
});
TypeScript
import Constants, { ExecutionEnvironment } from 'expo-constants';
import type { ExpoConfig } from 'expo/config';
const config: ExpoConfig | null = Constants.expoConfig;
const env: ExecutionEnvironment = Constants.executionEnvironment;
| Platform | Supported |
|---|
| iOS | ✅ |
| Android | ✅ |
| Web | ✅ |
On web, some device-specific constants may not be available or return default values.
Resources