Skip to main content

Installing and Initializing Projects

1. Installing Expo CLI

The Expo Command Line Interface (CLI) is the primary tool for creating, building, and managing Expo projects.

Installation Method Command Notes
npm npm install -g @expo/cli Installs the Expo CLI globally using npm
yarn yarn global add @expo/cli Installs the Expo CLI globally using Yarn
pnpm pnpm add -g @expo/cli Installs the Expo CLI globally using pnpm

Example: Verify Installation

expo --version
Note: Ensure Node.js (v18 or higher) is installed before installing the Expo CLI.

2. Creating New Project

Example: Using Expo CLI to create a new project

expo init MyApp
Option Values Description
--template blank, tabs, minimal Choose a template for the project structure
--name MyApp Name of the project directory
--sdkVersion 50.0.0 Expo SDK version to use (latest stable)
Note: The expo init command creates a new project with the Expo CLI. It will prompt you to select a template or use the default.

3. Choosing Project Template

When initializing a new Expo project, you can choose from several project templates to suit your development needs.

Template Description Use Case Language
blank A minimal template with no additional dependencies or features. Start from scratch or build a custom solution. JavaScript
tabs A template with a tab navigator and sample screens. Build a multi-screen app with navigation. JavaScript
bare A bare workflow project with native dependencies. Advanced use cases requiring native modules or custom configurations. JavaScript
with-typescript A blank template with TypeScript support pre-configured. Develop with type safety and modern tooling. TypeScript

Example: Initializing with Tabs Template

expo init --template tabs MyTabsApp
Note: The tabs template includes @react-navigation and sample screens to help you get started quickly.

Template Comparison

  • blank: Ideal for developers who want full control over their project setup.
  • tabs: Great for apps with multiple screens and navigation needs.
  • bare: Best for developers who need to integrate native modules or use custom configurations.
  • with-typescript: Perfect for teams that prefer type safety and structured development.

4. Installing Dependencies

Expo projects use npm or yarn to manage dependencies. You can install packages using the Expo CLI or directly with your package manager.

Command Description Example
npm install <package> Installs a package using npm npm install react-native
yarn add <package> Installs a package using yarn yarn add react-native
expo install <package> Installs a package compatible with Expo expo install react-native

Example: Installing a dependency with Expo CLI

expo install react-native-vector-icons
Note: Using expo install ensures that the package is compatible with Expo's managed workflow and handles versioning correctly.

Example: Installing with npm

npm install react-native-vector-icons

5. Understanding Project Structure

Directory/File Description Notes
app/ Contains the main application code Entry point is App.tsx or App.js
assets/ Static assets like images, fonts, and videos Use require() or import to reference
components/ Reusable UI components Organized by feature or purpose
constants/ Global constants and configuration values Used across the app for consistency
hooks/ Custom React hooks Encapsulate logic that can be reused across components
navigation/ Navigation setup using React Navigation Defines app flow and screen transitions
screens/ Individual screens or views Each screen is typically a separate file
services/ External API integrations and backend services Handles data fetching and business logic
utils/ Utility functions and helper methods Contains shared logic not tied to a specific component
babel.config.js Babel configuration for transpiling code Used to transform modern JavaScript into compatible versions
eas.json Configuration for EAS Build and Submit Defines build profiles and submission settings
expo-env.d.ts TypeScript declaration file for environment variables Enables type checking for environment variables
package.json Project metadata and dependencies Lists all installed packages and scripts
tsconfig.json TypeScript configuration file Defines how TypeScript should compile the project

Example: Basic App Structure

// app/App.tsx
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Hello, Expo!</Text>
    </View>
  );
}
Note: The app/ directory is the root of your application code. It's where you'll spend most of your time building features and components.

6. Initializing Git Repository

Example: Initialize Git repository

# Initialize a new Git repository
git init

# Add all files to staging
git add .

# Commit the initial state
git commit -m "Initial commit"
Command Description Notes
git init Creates a new Git repository Initializes a new Git repository in the current directory
git add . Adds all files to the staging area Stages all changes for the next commit
git commit -m "message" Commits changes to the repository Saves the staged changes with a descriptive message
Note: It's recommended to initialize Git before starting your Expo project to track changes and manage version control effectively.

7. Setting Up TypeScript

Expo supports TypeScript out of the box. You can either create a new project with TypeScript or add it to an existing JavaScript project.

Step Description Action
Create new project with TypeScript Initialize a new Expo project using the TypeScript template. npx create-expo-app@latest my-app --template typescript
Add TypeScript to existing project Install required dependencies and configure TypeScript. npx expo install typescript @types/react @types/node

Example: Configure tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2020", "dom"],
    "types": ["node"]
  },
  "include": ["**/*.ts", "**/*.tsx"]
}
Note: Ensure that your project's tsconfig.json is properly configured to support React Native and Expo features.

8. Configuring Metro Bundler

Configuration Option Description Default Value Notes
metro.config.js Entry point for Metro configuration metro.config.js Used to customize Metro bundler behavior
resolver.assetExts Additional asset extensions to resolve ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tiff', 'webp', 'svg', 'mp4', 'mov', 'avi', 'wmv', 'webm', 'mp3', 'wav', 'ogg', 'aac', 'flac', 'm4a', 'wma'] Allows custom asset types to be resolved by Metro
resolver.sourceExts Additional source file extensions to resolve ['js', 'jsx', 'ts', 'tsx', 'mjs'] Allows custom source file extensions to be resolved by Metro
server.port Port to run the Metro server on 8081 Can be changed to avoid port conflicts

Example: Custom Metro Configuration

const config = {
  resolver: {
    assetExts: ['png', 'jpg', 'webp'],
    sourceExts: ['js', 'jsx', 'ts', 'tsx', 'mjs']
  },
  server: {
    port: 8082
  }
};

module.exports = config;
Note: The metro.config.js file is read by the Metro bundler at build time and can be used to customize how assets and modules are resolved.

9. Installing Expo Go App

The Expo Go app is required to run Expo projects on physical devices. It allows you to preview your app, scan QR codes, and interact with your project in real-time.

Platform Installation Method Notes
iOS Download from the App Store Search for "Expo Go" in the App Store and install the official app.
Android Download from Google Play Store Search for "Expo Go" in the Play Store and install the official app.
Windows/Mac Use Expo Go via Web Scan the QR code from your terminal or browser to preview on a device.

Example: Opening Expo Go on Device

After installing the Expo Go app, open it and allow camera permissions to scan QR codes.

Note: The Expo Go app is not required for development in the Expo Web environment or when using the Expo Dev Client.

10. Understanding Managed vs Bare Workflow

Aspect Managed Workflow Bare Workflow
Project Structure Pre-configured with Expo SDK Full native project setup
Native Code Access Restricted Full access to native modules
Expo SDK Required and managed Optional
Deployment Expo Go or EAS App Store / Play Store directly
Flexibility Less flexible Highly customizable
Build Process Managed by Expo Manual or EAS

Managed vs Bare Workflow Comparison

  • Managed Workflow: Ideal for rapid prototyping and simpler apps. Uses Expo SDK to abstract native code.
  • Bare Workflow: Offers full control over native modules and dependencies. Requires more setup but provides flexibility for complex apps.
Note: Switching from managed to bare workflow is possible but requires careful migration steps.

11. Using Expo Snacks

Expo Snack is a web-based development environment that allows you to write, run, and share Expo projects directly in the browser. It's a great way to prototype ideas or experiment with new features without setting up a local development environment.

Feature Description Availability
Web-based IDE Write and run code in the browser without installing anything locally. NEW
Real-time Collaboration Share your project with others and collaborate in real time. NEW
No Setup Required Start coding immediately with no local dependencies or configuration. NEW

Example: Creating a New Snack

// Import necessary modules
import React from 'react';
import { View, Text } from 'react-native';

// Create a basic component
export default function App() {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Hello from Expo Snack!</Text>
    </View>
  );
}
Note: Expo Snack supports most Expo APIs but has some limitations compared to a full local development setup. For example, certain native modules or advanced configurations might not be available.
Warning: Changes made in Expo Snack are not persisted unless you explicitly save your project. Make sure to export or fork your work regularly.

12. Upgrading Expo SDK Version

Upgrading the Expo SDK version involves updating your project's dependencies and making necessary code adjustments to align with the new SDK features and breaking changes.

Step Description Action
Check Current SDK Version Identify the current SDK version in your project. expo --version
Update SDK Version Modify the expo dependency in package.json. "expo": "^51.0.0"
Install Dependencies Run npm install or yarn install to update dependencies. npm install
Update Configuration Adjust configuration files like app.json if needed. { "expo": { "sdkVersion": "51.0.0" } }
Test Compatibility Verify that all features and plugins are compatible with the new SDK. Example: Testing import { version } from 'expo';\nconsole.log('SDK Version:', version);
Note: Always review the Expo SDK release notes for breaking changes and migration steps.

Was this article helpful?