New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

expo-server-sdk

Package Overview
Dependencies
Maintainers
15
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-server-sdk

Server side library for working with Expo using Node.js

3.1.0
Source
npm
Version published
Weekly downloads
154K
2.73%
Maintainers
15
Weekly downloads
 
Created

What is expo-server-sdk?

The expo-server-sdk is a Node.js library for sending push notifications to devices using the Expo push notification service. It allows you to send notifications to both iOS and Android devices with ease.

What are expo-server-sdk's main functionalities?

Sending Push Notifications

This feature allows you to send push notifications to multiple devices. The code sample demonstrates how to create a list of messages and send them in chunks using the Expo push notification service.

const { Expo } = require('expo-server-sdk');
let expo = new Expo();
let messages = [];
let somePushTokens = ['ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]', 'ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy]'];
for (let pushToken of somePushTokens) {
  if (!Expo.isExpoPushToken(pushToken)) {
    console.error(`Push token ${pushToken} is not a valid Expo push token`);
    continue;
  }
  messages.push({
    to: pushToken,
    sound: 'default',
    body: 'This is a test notification',
    data: { withSome: 'data' },
  });
}
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
  for (let chunk of chunks) {
    try {
      let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
      tickets.push(...ticketChunk);
    } catch (error) {
      console.error(error);
    }
  }
})();

Handling Receipts

This feature allows you to handle receipts for the notifications you have sent. The code sample demonstrates how to retrieve and process the status of sent notifications using their receipt IDs.

let receiptIds = ['xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'];
(async () => {
  try {
    let receipts = await expo.getPushNotificationReceiptsAsync(receiptIds);
    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) {
          console.error(`The error code is ${details.error}`);
        }
      }
    }
  } catch (error) {
    console.error(error);
  }
})();

Other packages similar to expo-server-sdk

Keywords

expo

FAQs

Package last updated on 04 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts