The `expo-server-sdk` is a server-side library for Node.js environments, designed to facilitate the sending of push notifications to mobile applications built with Expo. It provides utilities for constructing push notification messages, sending them efficiently to Expo's push notification service, and handling the resulting receipts and errors. The current stable version is 6.1.0. This SDK maintains an active release cadence, with recent major versions (v4, v5, v6) introducing significant breaking changes around module systems and Node.js version support. Key differentiators include its tight integration with the Expo ecosystem, simplifying the complex process of managing push tokens and batching messages, and providing a streamlined API for interacting with the Expo push service. It abstracts away much of the underlying HTTP request handling and error parsing.
npm install expo-server-sdkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing the Expo client, validating an Expo push token, constructing a push notification message, chunking and sending messages, and finally retrieving and processing push notification receipts to check for delivery status and errors.
Update all `require('expo-server-sdk')` statements to `import { SymbolName } from 'expo-server-sdk';`. Ensure your project's `package.json` specifies `"type": "module"` or uses `.mjs` file extensions for ESM compatibility.Remove any `useFcmV1` property from your `Expo` client initialization options, as it will cause a TypeScript error or be ignored at runtime.
No direct code change is typically required unless you were directly interacting with or patching `node-fetch` within the SDK's context. Ensure your Node.js environment is compatible with `undici` (Node.js >=16 for `undici` itself, but SDK requires >=20).
Upgrade your Node.js environment to version 20 or newer. Check your `engines` field in `package.json` and local development environment.
For versions before 5.0.0, consider removing the option as it would default to the recommended behavior. For v5.0.0 and above, its removal is mandatory.
Change `const Expo = require('expo-server-sdk');` to `import { Expo } from 'expo-server-sdk';` and ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for files importing ESM.Always validate tokens using `Expo.isExpoPushToken(token)` before attempting to send notifications. Ensure you are receiving valid tokens from Expo's client-side SDK.
Upgrade your Node.js installation to version 20 or newer. Use a Node.js version manager like `nvm` to easily switch versions (`nvm install 20 && nvm use 20`).
Implement robust error handling for push notification receipts. Log errors and potentially remove invalid/expired tokens from your database. For rate limits, consider implementing exponential backoff or reviewing your sending strategy.