Setting Up React Native Development Environment
# CHAPTER 2
Setting Up React Native Development Environment
1. Introduction
Setting up a mobile development environment is historically the most frustrating part of learning to build apps. You have to install heavy SDKs, configure system paths, and set up virtual emulators. Fortunately, the React Native community has created tools to drastically simplify this process. In this chapter, we will master Setting Up the React Native Development Environment. We will install Node.js, explain the critical difference between the Expo CLI and the React Native CLI, and configure our computers to run our very first mobile application.2. Learning Objectives
By the end of this chapter, you will be able to:- Install Node.js and verify npm is working.
- Understand the difference between Expo CLI and React Native CLI.
- Install the Expo Go app on your physical mobile device.
- Set up an Android Emulator using Android Studio (Optional but recommended).
- Initialize a new React Native project.
3. Step 1: Installing Node.js
Because React Native uses JavaScript, your computer needs a JavaScript runtime engine.- 1. Go to nodejs.org and download the LTS (Long Term Support) version for Windows or Mac.
- 2. Run the installer and accept all default settings.
-
3.
To verify it worked, open your computer's terminal (or Command Prompt) and type:
node -v
-
4.
Also verify npm (Node Package Manager) by typing:
npm -v
4. Expo CLI vs React Native CLI
There are two ways to build a React Native app. This is the most important decision you will make.1. Expo CLI (Recommended for Beginners & 90% of Apps):
- Pros: Incredibly easy setup. No need to install Android Studio or Xcode. You can test iOS apps on a Windows PC! It comes with pre-configured packages for Camera, Maps, and Notifications.
- Cons: You don't have direct access to the native iOS/Android folders (unless you "eject" or use Expo prebuild).
2. React Native CLI (The "Bare Workflow"):
-
Pros: Full control. You have direct access to the
android/andios/folders to write custom Java or Swift code.
- Cons: Setup takes hours. You MUST have a Mac to compile for iOS. Prone to frustrating native build errors.
*In this course, we will use Expo, as it is the official recommendation of the React Native core team for starting new projects.*
5. Step 2: Creating an Expo Project
You do not need to install Expo globally anymore. We will usenpx (which comes with Node.js) to fetch and run the latest Expo tool instantly.
- 1. Open your terminal.
-
2.
Navigate to your desktop (or coding folder):
cd Desktop
- 3. Run the setup command:
- 4. Wait for the tool to download the template and install the node modules.
-
5.
Move into your new folder:
cd MyFirstApp
6. Step 3: Running the App on a Physical Device
The absolute easiest way to test your app is on your actual phone. Emulators are heavy and slow down older computers.- 1. Download the Expo Go app from the Apple App Store or Google Play Store on your physical phone.
- 2. Ensure your phone and your computer are connected to the exact same Wi-Fi network.
- 3. In your computer's terminal, start the local server:
- 4. A massive QR code will appear in your terminal!
- 5. Open the Expo Go app on Android (or the Camera app on iPhone) and scan the QR code.
- 6. Your app will wirelessly bundle and appear on your phone!
7. Step 4: Setting up Emulators (Optional but Recommended)
If you want to code on one screen without looking down at your phone, you need an Emulator.- For Android (Windows/Mac): Download Android Studio. During installation, ensure "Android Virtual Device (AVD)" is checked. Open Android Studio -> Virtual Device Manager -> Create a Pixel phone emulator and launch it.
- For iOS (Mac Only): Download Xcode from the Mac App Store. Open Xcode -> Go to Preferences -> Locations -> Ensure Command Line Tools are selected. Open the Simulator app.
Once your emulator is running, press a (for Android) or i (for iOS) in your npx expo start terminal, and Expo will automatically install the app onto the virtual phone!
8. Visual Learning: The Expo Workflow
9. Common Mistakes
- Network Errors with Expo Go: If you scan the QR code and your phone says "Network Connection failed," it is almost always because your PC and phone are on different Wi-Fi networks (e.g., PC on Ethernet, phone on Wi-Fi, or a strict corporate firewall blocking local ports).
- Fix: Connect both to the same Wi-Fi, or plug your phone into the PC via USB.
10. Best Practices
- Use Visual Studio Code: Download VS Code as your code editor. Install the following extensions: ES7+ React/Redux/React-Native snippets (for code autocomplete) and Prettier (to format your code beautifully on save).
11. Practice Exercises
-
1.
What command line tool provided by Node.js is used to instantly execute the
create-expo-appscript without installing it globally?
- 2. If you are developing on a Windows machine, can you view an iOS version of your app on a physical iPhone using Expo Go?
12. MCQs with Answers
Why is the Expo CLI generally recommended over the React Native CLI for beginners and prototyping?
When starting your development server using npx expo start, what software component is actually bundling your JavaScript code and serving it to your mobile device?
13. Interview Questions
- Q: Explain the fundamental differences between a "Bare Workflow" (React Native CLI) and a "Managed Workflow" (Expo). In what specific scenario would a CTO be forced to eject from Expo to the Bare workflow?
- Q: Walk me through the local network requirements and communication flow that allows the Expo Go app to instantly hot-reload JavaScript code from your computer's IDE to a physical mobile device.
-
Q: What is the
node_modulesfolder, and why must it always be included in a.gitignorefile?