npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@startupjs/push-notifications

v0.61.0

Published

Push notifications module

Readme

Push Notifications

!IMPORTANT! The package only works on ios and android platforms!

Dependencies

@react-native-community/push-notification-ios >= 1.8.0
react-native-push-notification >= 7.2.3

Installation

yarn add @startupjs/push-notifications @react-native-community/push-notification-ios react-native-push-notification

Connecting certificates

Create p8 certificate

In order to send push notifications to ios devices, you need to create certificates.

Login to your Apple Developer account.

Select Certificates, Identifiers & Profiles and go to Keys. Click the + circle button to create a new key.

Certificates, Identifiers & Profiles

Give it a name and enable the Apple Push Notifications service (APNs). Choose Continue and on the next screen choose Register.

Apple Push Notifications service (APNs)

It is important to record the following three elements from this page:

  • Select Download to save the p8 file locally. You will need to upload this to Firebase. You will not be able to download this certificate by leaving this page.
  • Copy and save the Key ID.
  • Copy and save your membership ID. It is located next to your name in the upper right corner of the Membership Center or in the Membership Details section.

Command id and key id

Setting up a Firebase project

You need to connect the p8 certificate to your application in Firebase. In your Firebase project, select the gear next to Project Overview and select Project settings:

Firebase settings

Then set up your iOS app in the General section of your project settings. Do all the operations indicated:

Add ios app

Then upload your p8 certificate by going to Cloud Messaging in the Firebase project settings. In the APNs Authentication Key section, select Upload.

Add APNs Authentication Key

Enter the details that you saved in the step of creating the p8 certificate.

iOS

Add Capabilities : Background Mode - Remote Notifications Go into your MyReactProject/ios dir and open MyProject.xcworkspace workspace with xcode. Select the top project MyProject and select the Signing & Capabilities tab. Add a 2 new Capabilities using + button:

Apple XCode Capabilities

Background Mode capability and tick Remote Notifications. Push Notifications capability

Background mode

Push Notifications

Remote Notifications

Connecting the package to your project

server

import { initFirebaseApp, initPushNotifications } from '@startupjs/push-notifications/server'

const serviceAccountPath = path.join(process.cwd(), 'path/to/serviceAccountKey.json')

...

init({ orm })
initFirebaseApp(serviceAccountPath)

...

startupjsServer({
  ...
}, (ee, options) => {
  ...
  initPushNotifications(ee)
  ...
}

You can generate a serviceAccount in the Firebase console of your application. Open the Service accounts tab and click Generate new private key.

Generate private key

client

Call initPushNotifications in the place where you need to initialize the device token of the current user (devices are written based on the userId from the current session). It makes sense to perform initialization only for an authorized user. But, if necessary, initialization is allowed for each visitor, for this functions can be called directly in the useGlobalInit callback of App.

import { initPushNotifications, notifications } from '@startupjs/push-notifications'
...

App(
  ...
  apps={ ..., notifications }
  useGlobalInit=() => {
    initPushNotifications()
    return true
  }
)

Usage server API

initPushNotifications (ee)

Initialization of push notifications on the server.

Arguments ee (Object) - eventEmitter of server.

Example

startupjsServer({ ... }, (ee, options) => {
  ...
  initPushNotifications(ee)
  ...
}

initFirebaseApp(serviceAccount)

Initialization of the Firebase application. How to create a serviceAccount see above.

Arguments serviceAccountPath (String) - the absolute path to serviceAccount.

Example

import { initFirebaseApp, initPushNotifications } from '@startupjs/push-notifications/server'

init({ orm })
initFirebaseApp(serviceAccountPath)

sendNotification (userIds, options)

The function of sending push notifications. Same as client function.

Usage client API

initPushNotifications (options)

function of initializing push notifications.

Arguments options [Object] - an options object for initializing push notifications. A complete list of options can be found in the documentation. !!IMPORTANT!! It is highly discouraged to override the onRegister and onNotification [Function] fields as this may break the package's behavior.

Example

App(
  ...
  useGlobalInit=() => {
    initPushNotifications()
    return true
  }
)

sendNotification (userIds, options)

function for sending notifications.

Arguments userIds [Array] - array of user id to which push notification will be sent.

options [Object]:

  • title [String] - header string.
  • body [String] (required) - content string.
  • platforms [Array] - an array of platforms to send notification to. If not specified, the message will be sent to all registered devices.

Example

function getPlan (id) {
  // WARNING: This is abstract example
  // This can be any function of yours
  return { name: 'silver' }
}

async function subscribe (planId) {
  const plan = getPlan(planId)
  // plan subscription logic
  await sendNotification([userId], { title: 'Subscription ', body: `You have subscribed to plan ${plan.name}`, platforms: ['ios', 'android']})
}