Providers

jxpush supports multiple push notification providers, allowing you to switch between them seamlessly or use them in parallel (via multiple client instances).

Supported Providers

  • FCM (Firebase Cloud Messaging): Ideal for backend-to-device notifications on Android, iOS, and Web. Requires a service account.
  • Expo Push API: Perfect for React Native apps built with Expo. Simplifies token management and does not require Apple/Google credentials directly in your backend.

Configuring Providers

You select a provider when initializing the PushClient.

Expo Provider

typescript
import { PushClient, ProviderType } from 'jxpush';

const client = new PushClient({
    provider: ProviderType.EXPO,
    expo: {
        accessToken: process.env.EXPO_ACCESS_TOKEN, // Optional, for higher rate limits
    }
});

FCM Provider

typescript
import { PushClient, ProviderType } from 'jxpush';

const client = new PushClient({
    provider: ProviderType.FCM,
    fcm: {
        serviceAccountPath: './service-account.json',
        // OR
        serviceAccount: { /* JSON object */ }
    }
});