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 🙏

© 2025 – Pkg Stats / Ryan Hefner

web-notifier

v2.0.3

Published

Easily send push notifications to your users through a service worker!

Downloads

7

Readme

Web Notifier

web-notifier is a an backend library for abstracting push notification logic in Node.

We take care of the hard stuff:

  • Sending notifications
  • Managing push subscriptions
  • Notification scheduling

The goal of this library is to abstract away the notification queue and validation logic and allow you to focus on your business logic.

Getting Started

Follow these steps to get the server logic setup quickly.

  1. Install the dependency

    npm i -S web-notifier
  2. Before we continue, you'll need to generate valid VAPID keys (if you haven't already) and store them for future use.

    npx web-push generate-vapid-keys

    There are two VAPID keys:

    • private key which should not be publicly accessible.
    • public key which can referenced in your frontend code.

    We recommend using a tool like dotenv to manage both public and private keys.

  3. Instantiate an instance on the server

import WebNotifier, { InMemoryAdapter } "web-notifier";

const notifier = new WebNotifier({
  vapidKeys: {
    publicKey: process.env.VAPID_PUBLIC_KEY,
    privateKey: process.env.VAPID_PRIVATE_KEY,
    email: process.env.VAPID_EMAIL,
  },
  notificationDefaults: {
    badge: "/notification-badge.png",
    icon: "/android-chrome-192x192.png",
    url: "/",
  },
  getUserPushSubscriptions,
  removeUserPushSubscriptions,
  adapter: new InMemoryAdapter(),
});
  1. Send a push notification
notifier.send(userId, {
  title: "This will send immediately",
});

You can also defer the message till a later date by using

const when = new Date();
when.setHours(when.getHours() + 1);
notifier.schedule(when, userId, {
  title: "This will send in 1 hour",
});

Adapters

WebNotifier needs to store information somewhere. The following information needs to be stored:

  • Notification Queue - When you call notifier.schedule or notifier.send we store the notification and payload. We then periodically crawl storage for notifications that are ready to be sent.

The following adapters are available:

  • InMemory - DO NOT USE THIS IN PRODUCTION - It's used to quickly scaffold and test, but the storage mechanism should be resilient to server restarts.

  • MongoDb - This leverages MongoDB and mongoose as a storage mechanism

  • CoreAdapter - If you need to implement your own storage mechanism for another service, the implementation should extend from CoreAdapter. InMemory adapter will be a good reference of how to properly construct an adapter.

Managing User Subscriptions

One thing this package does not do is user subscription management. From the client, you will receive a push subscription address. You'll need to store this and associate it with a user.

WebNotifier expects the following functions passed in:

  • getUserPushSubscriptions - this function will provide a userId and it should return an array of push subscriptions to send to. You can provide one or a million, it will slowly send them as the resources are available.
  • removeUserPushSubscriptions - Sometimes, users will block your push notifications. This function will allow you to remove a push subscription from a user.