All Projects → expo → Expo Server Sdk Node

expo / Expo Server Sdk Node

Licence: mit
Server-side library for working with Expo using Node.js

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Expo Server Sdk Node

expo-reason-starter
This project allows you to quickly get started with building mobile apps in ReasonML/ReScript
Stars: ✭ 16 (-96.54%)
Mutual labels:  expo
Expo Cljs Template
Expo template for Clojurescript React Native
Stars: ✭ 281 (-39.31%)
Mutual labels:  expo
React Native Version
🔢 Version your React Native or Expo app in a `npm version` fashion.
Stars: ✭ 408 (-11.88%)
Mutual labels:  expo
expo-soundcloud-clone
soundcloud clone built with expo
Stars: ✭ 47 (-89.85%)
Mutual labels:  expo
Rn Tourguide
🚩Make an interactive step by step tour guide for your react-native app (a rewrite of react-native-copilot)
Stars: ✭ 269 (-41.9%)
Mutual labels:  expo
Mobile App
See your city's air pollution measured in daily cigarettes. iOS/Android.
Stars: ✭ 291 (-37.15%)
Mutual labels:  expo
expo-with-storybook-howto
How to setup an Expo-based React Native project to use Storybook
Stars: ✭ 41 (-91.14%)
Mutual labels:  expo
Expo Three
Utilities for using THREE.js on Expo
Stars: ✭ 432 (-6.7%)
Mutual labels:  expo
Expo Github Action
Expo CLI in your GitHub Actions workflow
Stars: ✭ 281 (-39.31%)
Mutual labels:  expo
Firebase Instagram
📸 Instagram clone with Firebase Cloud Firestore, Expo, and React Native 😁😍
Stars: ✭ 389 (-15.98%)
Mutual labels:  expo
Instagram
A universal instagram clone built with Expo
Stars: ✭ 258 (-44.28%)
Mutual labels:  expo
React Native User Profile
🎨 A react native mobile starter kit, Examples of user profiles screens to help you write component and design
Stars: ✭ 259 (-44.06%)
Mutual labels:  expo
Expo Netflix
Netflix UI Clone with React Native & Expo || web support => https://expo-netflix.vercel.app
Stars: ✭ 297 (-35.85%)
Mutual labels:  expo
taro-playground
The Taro Playground App is a cross-platform application developed using Taro, to help developers develop and debug Taro applications.
Stars: ✭ 33 (-92.87%)
Mutual labels:  expo
Bangumi
💫 An unofficial bgm.tv app client for Android and iOS, built with React Native. 类似专门做ACG的豆瓣, 已适配 iOS/Android, mobile/Pad, light/dark theme, 并加入了很多独有的增强功能
Stars: ✭ 409 (-11.66%)
Mutual labels:  expo
CRUDReactNativeSQLite
CRUD de app em React Native utilizando armazenamento local com SQLite
Stars: ✭ 16 (-96.54%)
Mutual labels:  expo
Expo Spotify
Spotify UI Clone with React Native & Expo || web support => https://expo-spotify.vercel.app
Stars: ✭ 287 (-38.01%)
Mutual labels:  expo
React Native Pull Refresh
Custom pull to refresh component for Android
Stars: ✭ 456 (-1.51%)
Mutual labels:  expo
React Native Svg Animated Linear Gradient
A wrap SVG component for animated linear gradient
Stars: ✭ 418 (-9.72%)
Mutual labels:  expo
React Native Dating App
Dating app - Exponent and React Native
Stars: ✭ 352 (-23.97%)
Mutual labels:  expo

expo-server-sdk-node Tests codecov

Server-side library for working with Expo using Node.js.

If you have problems with the code in this repository, please file issues & bug reports at https://github.com/expo/expo. Thanks!

Usage

Note: the following code assumes that you are using JavaScript modules with import. If you aren't then you should use the old syntax for the SDK import: const { Expo } = require('expo-server-sdk').

yarn add expo-server-sdk
import { Expo } from 'expo-server-sdk';

// Create a new Expo SDK client
// optionally providing an access token if you have enabled push security
let expo = new Expo({ accessToken: process.env.EXPO_ACCESS_TOKEN });

// Create the messages that you want to send to clients
let messages = [];
for (let pushToken of somePushTokens) {
  // Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]

  // Check that all your push tokens appear to be valid Expo push tokens
  if (!Expo.isExpoPushToken(pushToken)) {
    console.error(`Push token ${pushToken} is not a valid Expo push token`);
    continue;
  }

  // Construct a message (see https://docs.expo.io/push-notifications/sending-notifications/)
  messages.push({
    to: pushToken,
    sound: 'default',
    body: 'This is a test notification',
    data: { withSome: 'data' },
  })
}

// The Expo push notification service accepts batches of notifications so
// that you don't need to send 1000 requests to send 1000 notifications. We
// recommend you batch your notifications to reduce the number of requests
// and to compress them (notifications with similar content will get
// compressed).
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
  // Send the chunks to the Expo push notification service. There are
  // different strategies you could use. A simple one is to send one chunk at a
  // time, which nicely spreads the load out over time:
  for (let chunk of chunks) {
    try {
      let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
      console.log(ticketChunk);
      tickets.push(...ticketChunk);
      // NOTE: If a ticket contains an error code in ticket.details.error, you
      // must handle it appropriately. The error codes are listed in the Expo
      // documentation:
      // https://docs.expo.io/push-notifications/sending-notifications/#individual-errors
    } catch (error) {
      console.error(error);
    }
  }
})();

...

// Later, after the Expo push notification service has delivered the
// notifications to Apple or Google (usually quickly, but allow the the service
// up to 30 minutes when under load), a "receipt" for each notification is
// created. The receipts will be available for at least a day; stale receipts
// are deleted.
//
// The ID of each receipt is sent back in the response "ticket" for each
// notification. In summary, sending a notification produces a ticket, which
// contains a receipt ID you later use to get the receipt.
//
// The receipts may contain error codes to which you must respond. In
// particular, Apple or Google may block apps that continue to send
// notifications to devices that have blocked notifications or have uninstalled
// your app. Expo does not control this policy and sends back the feedback from
// Apple and Google so you can handle it appropriately.
let receiptIds = [];
for (let ticket of tickets) {
  // NOTE: Not all tickets have IDs; for example, tickets for notifications
  // that could not be enqueued will have error information and no receipt ID.
  if (ticket.id) {
    receiptIds.push(ticket.id);
  }
}

let receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
(async () => {
  // Like sending notifications, there are different strategies you could use
  // to retrieve batches of receipts from the Expo service.
  for (let chunk of receiptIdChunks) {
    try {
      let receipts = await expo.getPushNotificationReceiptsAsync(chunk);
      console.log(receipts);

      // The receipts specify whether Apple or Google successfully received the
      // notification and information about an error, if one occurred.
      for (let receiptId in receipts) {
        let { status, message, details } = receipts[receiptId];
        if (status === 'ok') {
          continue;
        } else if (status === 'error') {
          console.error(
            `There was an error sending a notification: ${message}`
          );
          if (details && details.error) {
            // The error codes are listed in the Expo documentation:
            // https://docs.expo.io/push-notifications/sending-notifications/#individual-errors
            // You must handle the errors appropriately.
            console.error(`The error code is ${details.error}`);
          }
        }
      }
    } catch (error) {
      console.error(error);
    }
  }
})();

Developing

The source code is in the src/ directory and babel is used to turn it into ES5 that goes in the build/ directory.

To build, npm run build.

To build and watch for changes, npm run watch.

See Also

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].