Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    Node.js Server SDK

    The SDK includes a typings file for TypeScript compatibility.

    ∞ Installation

    The Beams Node.js server SDK is available on NPM here.

    ∞ Install

    You can install this SDK by using NPM or Yarn:

    npm install @pusher/push-notifications-server --save
    yarn add @pusher/push-notifications-server

    ∞ Reference

    ∞ constructor PushNotifications

    new PushNotifications(options)

    Construct a new Pusher Beams Client connected to your Beams instance.

    You only need to do this once.

    ∞ Arguments

    ∞ optionsObject Required
    • instanceId (String | Required) - The unique identifier for your Beams instance. This can be found in the dashboard under “Credentials”.
    • secretKey (String | Required) - The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.

    ∞ Returns

    A Pusher Beams client

    ∞ Example

    const PushNotifications = require("${SDK_NAME}");

    let beamsClient = new PushNotifications({
    instanceId: "YOUR_INSTANCE_ID_HERE",
    secretKey: "YOUR_SECRET_KEY_HERE",
    });

    ∞ .publishToInterests

    Publish a push notification to devices subscribed to given Interests, with the given payload.

    ∞ Arguments

    ∞ interestsArray<String> Required

    Interests to send the push notification to, ranging from 1 to 100 per publish request. See Concept: Device Interests.

    ∞ publishBodyObject

    See publish API reference.

    ∞ Returns

    (Promise) - A promise that resolves to a publishResponse. See publish API reference.

    ∞ Example

    beamsClient
    .publishToInterests(["hello"], {
    apns: {
    aps: {
    alert: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    },
    fcm: {
    notification: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    web: {
    notification: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    })
    .then((publishResponse) => {
    console.log("Just published:", publishResponse.publishId);
    })
    .catch((error) => {
    console.error("Error:", error);
    });

    ∞ .publishToUsers

    Publish a push notification to devices belonging to specific users, with the given payload.

    ∞ Arguments

    ∞ userIDsArray<String> Required

    User IDs to send the push notification to, ranging from 1 to 1000 per publish request. See Concept: Authenticated Users.

    ∞ publishBodyObject

    See publish API reference.

    ∞ Returns

    (Promise) - A promise that resolves to a publishResponse. See publish API reference.

    ∞ Example

    beamsClient
    .publishToUsers(["user-001", "user-002"], {
    apns: {
    aps: {
    alert: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    },
    fcm: {
    notification: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    web: {
    notification: {
    title: "Hello",
    body: "Hello, world!",
    },
    },
    })
    .then((publishResponse) => {
    console.log("Just published:", publishResponse.publishId);
    })
    .catch((error) => {
    console.error("Error:", error);
    });

    ∞ .generateToken

    Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.

    ∞ Arguments

    ∞ userIDString Required

    User ID of the user for whom you want to generate a Beams token.

    ∞ Returns

    A Beams token for the given user.

    ∞ Example

    const beamsToken = beamsClient.generateToken("user-001");

    ∞ .deleteUser

    Delete a user and all their devices from Pusher Beams.

    ∞ Arguments

    ∞ userIDString Required

    The user ID of the user you wish to delete.

    ∞ Returns

    (Promise) - A promise that resolves with no arguments. If deletion fails, the promise will reject.

    ∞ Example

    beamsClient
    .deleteUser("user-001")
    .then(() => {
    console.log("Successfully deleted the user!");
    })
    .catch((error) => {
    console.error("Error:", error);
    });

    Contents

    • Installation
      • Install
    • Reference
      • constructor PushNotifications
      • .publishToInterests
      • .publishToUsers
      • .generateToken
      • .deleteUser

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2024 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord