Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@pusher/push-notifications-server

pusher59.3kMIT1.2.7TypeScript support: included

NodeJS Server SDK for Pusher Push Notifications

push notifications, notifications, pusher, realtime

readme

Build npm npm

Pusher Beams Node.js Server SDK

Full documentation for this SDK can be found here

Installation

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

You can install this SDK by using npm:

$ npm install @pusher/push-notifications-server --save

Or yarn if you prefer:

$ yarn add @pusher/push-notifications-server

Usage

Configuring the SDK for Your Instance

Use your instance id and secret (you can get these from the dashboard) to create a Beams PushNotifications instance:

const PushNotifications = require('@pusher/push-notifications-server');

let pushNotifications = new PushNotifications({
  instanceId: 'YOUR_INSTANCE_ID_HERE',
  secretKey: 'YOUR_SECRET_KEY_HERE'
});

Publishing a Notification

Once you have created your Beams PushNotifications instance, you can immediately publish a push notification to your devices, using Device Interests:

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

changelog

Changelog

1.2.7

  • [CHANGED] jsonwebtoken package version from v8 to v9

1.2.6

  • [FIXED] Fix the hide_notification_if_site_has_focus TypeScript
  • [FIXED] Fixes the incorrect TypeScript signature for the generateToken function

1.2.5

  • [CHANGED] Added data type for ApnsPayload

1.2.4

  • [CHANGED] Remove some redundant steps from release action

1.2.3

  • [CHANGED] Switch from Travis CI to GH actions

1.2.2

  • [REMOVED] requests dependency and replaced with standard library

1.2.1

  • [FIXED] Added missing TypeScript types for web push publish payload

1.2.0

  • [ADDED] More payload fields to TypeScript bindings (collapse_key, expiration, etc.)

1.1.1

  • [FIXED] Fixes double JSON encoding

1.1.0

  • [ADDED] Support for publishing to Authenticated Users
  • [ADDED] TypeScript typings for Authenticated Users
  • [DEPRECATED] Deprecates publish in favour of publishToInterests

1.0.1

  • [FIXED] Accessing property on undefined object on non-json response

1.0.0

  • [ADDED] Changelog for GA release