Expo device networking
You can open the Metro-served app on an emulator and phone and point it at your laptop's API over the LAN.
Learning outcomes
- Distinguish Metro from the Go API and understand why the phone connects to both.
- Run the Expo app on an Android emulator and a physical phone using Expo Go.
- Configure the laptop's LAN IP so the phone can reach the Go API.
- Read the API address through EXPO_PUBLIC_API_URL and understand why public environment variables cannot contain secrets.
- Diagnose network failures by checking the phone's connection to the API before debugging application code.
Your Expo app runs on your laptop during development, but you need to open it on an Android emulator and a physical phone. Both devices must load the JavaScript bundle and reach the Go API that serves restaurants, menus and orders. These are two separate network connections, and getting one working does not guarantee that the other works.
Two development servers
Your laptop runs two servers while you develop the app. Each has a different responsibility.
- Metro is the JavaScript bundler and development server. Running
npx expo startinapp/starts Metro on port8081. It bundles your TypeScript files and serves the JavaScript bundle to the emulator or phone. - The Go API runs on port
8080. It serves the data used by the app, including authentication, restaurants, menus and orders. You start it separately withmake runfrombackend/.
The app needs both connections. Metro provides the code that executes on the device. The API provides the data that the code requests.


Starting Metro does not start the Go API. You can successfully open the app while every request to the backend fails.
Likewise, the API can be healthy while the phone cannot load the application because Metro is unreachable.
Expo Go on a physical phone
Expo Go lets you run the app on a physical device without building an APK. It contains the native runtime and supported native modules for its Expo SDK, along with a loader that fetches your JavaScript bundle from Metro.
The development flow is:
- Connect your phone and laptop to the same Wi-Fi network.
- Run
npx expo startinsideapp/. - Open Expo Go on Android, or use the Camera app on iOS, to scan the QR code.
- Expo Go connects to Metro and downloads the JavaScript bundle.
- The app opens on your phone.
The project uses Expo SDK 58 with React Native 0.88. The libraries used this week, including Expo Router, expo-secure-store, @react-native-async-storage/async-storage and react-native-safe-area-context, are included in the SDK-compatible Expo Go runtime.
Your installed Expo Go must support the project's SDK version. If the native runtime does not match the project, the app may fail to load even when Metro is running correctly.
The Android emulator
You can also run the app in an Android emulator without using a physical phone.
Create an Android virtual device through Android Studio's Device Manager. Start the emulator and wait until its home screen appears.
With Metro running, press a in the Expo CLI terminal:
cd app && npx expo startExpo opens the Android emulator and installs Expo Go if necessary. The emulator then loads the JavaScript bundle from Metro.
There is one networking detail specific to Android emulators. The special address 10.0.2.2 refers to the laptop's loopback interface from the emulator. It can therefore reach a Go API running on the laptop through http://10.0.2.2:8080.
This course uses the laptop's LAN IP instead. That keeps the API URL consistent between the emulator and physical devices.
Localhost and the LAN IP
The most common networking mistake is using localhost as the API address.
localhost means the device making the request. When the Go API runs on your laptop, http://localhost:8080 works in the laptop's browser. When the app sends that same request from a physical phone, localhost refers to the phone.
The phone tries to reach port 8080 on itself. Your Go API is running on the laptop, so the request fails with a network error.
You need the laptop's LAN IP, the address assigned to it by the Wi-Fi network.
On macOS, run:
ipconfig getifaddr en0The command prints the LAN address of the network interface. For example:
192.168.1.42You can then construct the API address:
http://192.168.1.42:8080The phone and laptop must be able to communicate over the same local network. A LAN IP does not make the API publicly accessible. It identifies the laptop within that network.
The address can change when you reconnect to Wi-Fi or restart your laptop. Check it again when a previously working connection stops working.
Public Expo environment variables
The LAN IP differs between developers and networks. You should not hardcode it into the application source.
Expo reads environment files when Metro starts. Variables with the EXPO_PUBLIC_ prefix become available in the JavaScript bundle as public Expo environment variables.
Put the actual address in app/.env.local:
EXPO_PUBLIC_API_URL=http://192.168.1.42:8080The Expo template already ignores .env.local, so your machine-specific configuration does not need to be committed.
Commit an .env.example file instead:
EXPO_PUBLIC_API_URL=http://<your LAN IP>:8080This tells another developer which variable to configure without committing your actual local setup.
Reading the API URL
Keep the environment lookup in one module, such as app/lib/config.ts. Other parts of the app can import API_URL rather than reading environment variables independently.
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
if (!apiUrl) {
throw new Error(
"EXPO_PUBLIC_API_URL is missing. Configure .env.local and restart Expo.",
);
}
export const API_URL = apiUrl.replace(/\/+$/, "");There is an important detail in the environment lookup. Metro statically replaces the exact expression process.env.EXPO_PUBLIC_API_URL when it builds the JavaScript bundle.
Do not use destructuring or a dynamic property lookup:
const { EXPO_PUBLIC_API_URL } = process.env;
const name = "EXPO_PUBLIC_API_URL";
const apiUrl = process.env[name];These expressions are not replaced in the same way. The result can be undefined on the device even when .env.local contains the variable.
The configuration also removes trailing slashes. This prevents URL construction from accidentally producing a double slash when the API client appends /v1/restaurants.
Restarting Metro after configuration changes
Metro reads the environment files when it starts. Reloading the app does not guarantee that a changed environment value will be included in the existing bundle.
After changing .env.local, stop Metro and start it again:
cd app && npx expo startIf the previous value still appears, clear the Metro cache:
cd app && npx expo start -cThis rebuilds the bundle using the current environment configuration.
Testing the network independently
When the app cannot reach the API, test the network before changing React Native code. This helps you separate an infrastructure problem from an application bug.
Start the Go backend:
cd backend && make runWith the backend running, open the health endpoint in the phone's browser:
http://192.168.1.42:8080/healthzReplace the example address with your laptop's actual LAN IP.
The phone's browser is a useful first check because it tests the same basic network path that the app needs to reach the API.
If the browser cannot load /healthz, investigate the network before inspecting the API client or screen components.
Common causes include:
| Problem | What to check |
|---|---|
| Different networks | Confirm the phone and laptop use the same Wi-Fi |
| Client isolation | Check whether the router prevents devices from communicating |
| macOS firewall | Allow incoming connections for the Go server |
| Incorrect bind address | Confirm the API listens on :8080, not 127.0.0.1:8080 |
| Incorrect LAN IP | Run ipconfig getifaddr en0 again |
Guest and office Wi-Fi networks often enable client isolation. This prevents connected devices from communicating with each other even when they appear to use the same Wi-Fi.
A phone hotspot is another option. Connect the laptop to the hotspot and use the laptop's address on that network.
Metro tunnel mode
Sometimes the phone cannot connect to Metro over the local network, even though the API connection is otherwise available.
You can start Metro using tunnel mode:
cd app && npx expo start --tunnelThis routes the Metro connection through a public tunnel instead of requiring a direct LAN connection to port 8081.
There is an important limitation: the tunnel is for Metro, not the Go API.
The app still reads EXPO_PUBLIC_API_URL and sends API requests to the laptop's LAN IP. The phone must still be able to reach port 8080 directly.
If the phone's browser cannot load /healthz, switching Metro to tunnel mode will not fix the API connection.
Applying device networking to the Expo app
The Expo app shell exercise brings these networking pieces together with the initial screen and navigation setup.
You will run the app on the Android emulator and a physical phone, configure EXPO_PUBLIC_API_URL, and verify that the phone can reach the Go API. The exercise also checks a restaurant deep link through Expo Router.
Keep the two connections separate when diagnosing problems. If the app does not load, check Metro on port 8081. If the app loads but cannot fetch backend data, check the API on port 8080.
Start with the phone's browser and /healthz. Once that works, you can investigate problems inside the app without confusing a network failure with a React Native rendering issue.
Check your understanding
You run npx expo start, scan the QR code and successfully open the app in Expo Go. However, the Restaurants screen cannot fetch data from the Go API. What should you check first?
References
Everything above is explained on this page; these are where it comes from (Expo SDK 58, Android Studio emulator (API 35)).