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

node-pushnotifications

v8.0.0

Published

Push notifications for Node.js. One API for FCM, APNs, Web Push, WNS and ADM.

Readme

node-pushnotifications

Push notifications for Node.js. One API for FCM, APNs, Web Push, WNS and ADM.

npm version npm downloads CI Node.js version License: MIT

const results = await push.send(
  [{ id: androidToken, type: FCM }, { id: iosToken, type: APN }, webSubscription],
  { title: 'Order shipped', body: 'Your order #1234 is on its way', topic: 'com.example.app' }
);

Contents

Features

  • Mix Android, iOS, web, Windows and Amazon devices in one send() call
  • Get the same result shape from every service, so you handle failures once
  • Built on firebase-admin, @parse/node-apn and web-push
  • APNs token (.p8) and certificate auth
  • Silent pushes on iOS and Android
  • Promise and callback APIs
  • TypeScript types included

Installation

npm install node-pushnotifications

Node.js 24 or later is required. The package is CommonJS, and it works with both require and import.

TypeScript types ship with the package and need TypeScript 5.5 or later and @types/node. If you have @types/node-pushnotifications installed, remove it. Annotate payloads as PushNotifications.Data so that fields like priority: 'normal' keep their literal types.

Quick start

import { readFileSync } from 'node:fs';
import PushNotifications, { FCM, APN } from 'node-pushnotifications';

const push = new PushNotifications({
  fcm: {
    appName: 'my-app',
    serviceAccountKey: JSON.parse(readFileSync('./firebase-service-account.json', 'utf8')),
  },
  apn: {
    token: { key: './AuthKey_ABC123DEFG.p8', keyId: 'ABC123DEFG', teamId: 'TEAM123456' },
    production: process.env.NODE_ENV === 'production',
  },
});

const results = await push.send(
  [
    { id: '<android-fcm-token>', type: FCM },
    { id: '<ios-apns-token>', type: APN },
  ],
  {
    title: 'Order shipped',
    body: 'Your order #1234 is on its way',
    topic: 'com.example.app', // your iOS bundle ID, required for APNs
    custom: { orderId: '1234' },
  }
);

for (const { method, success, failure } of results) {
  console.log(`${method}: ${success} sent, ${failure} failed`);
}

With CommonJS, use const PushNotifications = require('node-pushnotifications') and read the constants from it, for example PushNotifications.FCM.

Usage

Settings

Pass a settings object with a key for each service you use. You can leave out the services you don't need.

const push = new PushNotifications({
  fcm: {/* Firebase credentials */},
  apn: {/* APNs key or certificate */},
  web: {/* VAPID keys */},
  wns: {/* Windows credentials */},
  adm: {/* Amazon credentials */},
  isAlwaysUseFCM: false,
});

Each service's guide lists its options and explains how to get the credentials: FCM, APNs, Web Push, WNS and ADM.

With isAlwaysUseFCM: true, every destination except Web Push subscriptions is sent through FCM.

Settings are merged with the defaults one level deep. If you pass apn, it replaces the whole default apn object. To change settings later, call push.setOptions(settings), which also reconnects to APNs.

Destinations

A destination is an object with the device's token and its service. You can mix services in one call.

import { FCM, APN, WNS, ADM } from 'node-pushnotifications';

const devices = [
  { id: '<fcm-token>', type: FCM },
  { id: '<apns-device-token>', type: APN },
  { id: 'https://db5.notify.windows.com/?token=...', type: WNS },
  { id: 'amzn1.adm-registration.v3...', type: ADM },
  { endpoint: 'https://...', keys: { p256dh: '<key>', auth: '<secret>' } },
];

The last entry is a Web Push subscription, the object your service worker gets from pushManager.subscribe(). Any other object without both id and type is treated as one, unless it has a topic or condition and no endpoint.

FCM topics and conditions are destinations too, for example { type: FCM, topic: 'news' }. See Topics and conditions.

Plain strings still work, but we don't recommend them. The library has to guess the service from the token's format, and token formats can change. It checks these rules in order:

| Rule | Service | | -------------------------------- | -------------------------------------- | | isAlwaysUseFCM is true | fcm | | Starts with http | wns | | Matches /^(amzn[0-9]*.adm)/i | adm | | 64 or 160 hexadecimal characters | apn | | Longer than 64 characters | fcm | | Anything else | unknown, which is reported as failed |

Sending

send() returns a promise. You can also pass a Node-style callback as the third argument.

const results = await push.send(devices, data);

push.send(devices, data, (err, results) => {});

The promise is returned even when you pass a callback, and it rejects when a service fails. If you only use the callback, add .catch(() => {}) so the rejection isn't reported as unhandled.

data is one object for all services, and each service uses the fields that apply to it. A typical notification looks like this:

const data = {
  title: 'New message',
  body: 'You have a new message from Ana',
  topic: 'com.example.app',
  custom: { conversationId: '42' },
  badge: 3,
  sound: 'default',
};

The payload reference lists every field.

Results

send() resolves to an array with one entry for each service it used:

[
  {
    method: 'fcm',
    success: 1,
    failure: 1,
    message: [
      {
        regId: '<token>',
        originalRegId: '<token>',
        messageId: 'projects/my-app/messages/0:1700...',
        error: null,
      },
      {
        regId: '<expired-token>',
        originalRegId: '<expired-token>',
        error: FirebaseMessagingError,
        errorMsg: 'Requested entity was not found.',
      },
    ],
  },
  { method: 'apn', success: 1, failure: 0, message: [{ regId: '<token>', error: null }] },
];

success counts the notifications the service accepted. It doesn't confirm that they reached the device. method is one of 'fcm', 'apn', 'webPush', 'wns' or 'adm'. originalRegId and messageId are only set for FCM.

When a single device fails, the promise still resolves, and that device's entry has an error. This is how you find FCM tokens and Web Push subscriptions to delete:

const staleTokens = results
  .filter((r) => r.method === 'fcm')
  .flatMap((r) => r.message)
  .filter((m) => m.error?.code === 'messaging/registration-token-not-registered')
  .map((m) => m.regId);

const expiredSubscriptions = results
  .filter((r) => r.method === 'webPush')
  .flatMap((r) => r.message)
  .filter((m) => m.error?.statusCode === 404 || m.error?.statusCode === 410)
  .map((m) => m.regId);

In TypeScript, checking method narrows each entry's regId and error to that service's types.

When a whole service fails, for example because of wrong APNs credentials or an FCM project ID that can't be determined, the promise rejects. The results from the other services are lost in that case.

Destinations that the library can't route come back in an entry with method: 'unknown'. If you pass no destinations, nothing is sent and you get a single entry with method: 'none'.

Supported services

| Service | Platforms | You need | Guide | | ------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------- | ---------------------------- | | Firebase Cloud Messaging | Android, iOS with Firebase | A Firebase service account | FCM | | Apple Push Notification service | iOS, iPadOS, macOS, watchOS, tvOS | An APNs key or certificate | APNs | | Web Push | Browsers | A VAPID key pair | Web Push | | Windows Push Notification Services | Windows | A package SID and client secret | WNS | | Amazon Device Messaging | Fire TV, Fire tablets, Vega OS | An ADM client ID and secret | ADM |

Documentation

Upgrading

  • Version 7
    • Requires Node.js 24 or later.
    • FCM topics and conditions are now destinations: { type: 'fcm', topic } or { type: 'fcm', condition }. data.recipients didn't work in recent versions and now makes send() reject.
    • Uses firebase-admin 14. If you pass your own credential that isn't a service account credential, for example applicationDefault(), also set settings.fcm.projectId.
    • The package ships src/ instead of the Babel output in lib/. Deep imports change from node-pushnotifications/lib/... to node-pushnotifications/src/... (with import, include the .js extension and use the default import, e.g. import constants from 'node-pushnotifications/src/constants.js').
  • Version 6
    • Requires Node.js 20 or later.
  • Version 5
    • GCM was removed. Android notifications go through FCM, so replace settings.gcm with settings.fcm.

Contributing

Bug reports and pull requests are welcome. See CONTRIBUTING.md to get started, and use GitHub Issues for bugs and questions.

Security

Please report vulnerabilities privately, as described in SECURITY.md.

License

MIT © AppFeel