Walkthrough

Push Notifications

Expo's push service, your own server, both.

Expo's Push API is the easy mode for notifications: register the device, get an Expo push token, send it to your server, your server hits Expo's send endpoint. You don't deal with APNs or FCM directly. Once you've shipped, graduate to a service like OneSignal or build the APNs/FCM path if you need topics or rich payloads.

Steps · 0 / 3 done
  1. Install + request permission

    Permission must be asked at a moment that makes sense — not on first launch.

    npx expo install expo-notifications expo-device
    VerifyPackages installed.
  2. Register for a push token

    After the user does something that justifies notifications (sets a reminder, follows another user), get the token and send it to your backend.

    import * as Notifications from 'expo-notifications';
    const { status } = await Notifications.requestPermissionsAsync();
    if (status !== 'granted') return;
    const token = (await Notifications.getExpoPushTokenAsync({ projectId })).data;
    await fetch('/api/devices', { method: 'POST', body: JSON.stringify({ token }) });
    VerifyYour /api/devices endpoint stores the token against the user.
  3. Send a test push from your server

    Hit Expo's send endpoint with the token. No SDK needed.

    await fetch('https://exp.host/--/api/v2/push/send', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        to: token,
        title: 'Hello from the server',
        body: 'Push works.',
      }),
    });
    VerifyThe notification arrives on the device within ~5s.
Check your understanding
Q1. When should you ask for notification permission?
· Tick off the 3 step(s) above.
· Score 100% on the quiz.