Expo Router Server API

55.0.7 · active · verified Sun Apr 19

expo-server is a foundational server-side API and runtime library specifically designed for projects leveraging Expo Router. It provides essential utilities and adapters for implementing server-side logic, including API routes, server-side rendering (SSR), and React Server Components (RSC) within a universal Expo application. Functioning primarily in a WinterCG-compliant environment, it allows developers to define API endpoints using a file-based convention (e.g., `+api.ts`), handle HTTP requests, and manage sensitive data securely on the server. The package facilitates full-stack development within the Expo ecosystem, enabling consistent codebases across native, web, and server environments. Expo SDK, which this package is part of or closely aligned with, typically releases new major versions three to four times a year. The current stable version of the broader Expo SDK is 55.x.x, with `expo-server` itself having independent, though generally aligned, releases (e.g., 0.7.5 as seen on npm for `@expo/server`). A key differentiator is its tight integration with Expo Router's opinionated file-system routing and universal development paradigm.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a basic server-side API route using `expo-server` within an Expo Router project, including environment checks.

/* app.json */
{
  "expo": {
    "web": {
      "output": "server"
    }
  }
}

/* src/app/hello+api.ts */
// Ensure your project has 'web.output': 'server' in app.json for API routes to be bundled.
import { environment, origin } from 'expo-server';

export async function GET(request: Request) {
  const url = new URL(request.url);
  const name = url.searchParams.get('name') || 'world';
  
  console.log(`API Call received from origin: ${origin()}`);
  console.log(`Running in environment: ${environment()}`);

  return Response.json({
    message: `Hello, ${name}! This is a server-side API route.`,
    isProduction: environment() === 'production',
    currentOrigin: origin()
  });
}

// To test, run `npx expo start` and then navigate to `http://localhost:8081/hello` or `http://localhost:8081/hello?name=Alice` in your browser or a tool like curl.
// In a native app, you would fetch from `/hello` and Expo Router would correctly proxy it to the server.

view raw JSON →