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

pwa-notifications

v1.0.3

Published

Framework-agnostic PWA and Push Notifications library

Readme

PWA Notifications

Latest Version Total Downloads License

A framework-agnostic, zero-config toolkit designed to instantly equip your web applications with robust Progressive Web App (PWA) capabilities and Push Notifications. It handles the heavy lifting of service worker registration, VAPID key generation, manifest injection, and provides beautiful UI components.

Features

  • Zero-Config Auto-Injection: Automatically injects manifest.json, standard PWA icons, and necessary code into Next.js layout upon installation.
  • Auto-Generated VAPID Keys: Safely generates and injects your push notification VAPID keys into .env.local or .env.
  • Universal Installation Prompts: Detects user OS and provides tailored installation instructions for iOS, Android, and Desktop.
  • Push Notification Management: Client hooks and server-side utilities for robust notification subscription and sending.
  • Framework Agnostic Core: Works flawlessly in Next.js, standard React (Vite/CRA), Vue, and Svelte.

Quick Installation

npm install pwa-notifications

Post-Installation

If you are using Next.js, a postinstall script runs automatically:

  1. Generates manifest.json and PWA icons in public/.
  2. Creates reusable React UI components in components/pwa-notifications/.
  3. Injects the EnableNotifications banner into app/layout.tsx.
  4. Creates a notification settings page at app/settings/notifications/page.tsx.
  5. Generates Firebase-compatible VAPID keys into .env.local.

For Standard React (Vite) or Vue, the script generates VAPID keys and public/sw.js, but you will manually assemble the UI using the provided API.

Usage

Usage in Next.js

Components are auto-injected directly into your components/pwa-notifications/ folder for complete freedom to customize.

  • EnableNotifications: A sleek, sticky banner auto-injected at the bottom of your layout.
  • InstallPrompt: OS-specific instructions modal (iOS Share, Android Chrome Menu, etc.).
  • PushNotificationManager: Customizable settings block showing subscription status.
  • InstallSection: Massive, highly-visual marketing block for your homepage.

Usage in Standard React (Vite / CRA)

import { useEffect, useState } from "react";
import {
  registerServiceWorker,
  subscribeToPush,
  isPushSupported,
  onPWAInstallable,
  promptPWAInstall,
} from "pwa-notifications/client";

export default function App() {
  const [canInstall, setCanInstall] = useState(false);

  useEffect(() => {
    registerServiceWorker("/sw.js");
    return onPWAInstallable((installable) => setCanInstall(installable));
  }, []);

  const handleSubscribe = async () => {
    if (!isPushSupported()) return alert("Push not supported!");
    const subscription = await subscribeToPush({
      vapidKey: import.meta.env.VITE_VAPID_PUBLIC_KEY, // Adjust based on your bundler
    });
    // Send subscription to your backend
  };

  return (
    <div>
      <button onClick={handleSubscribe}>Enable Notifications</button>
      {canInstall && <button onClick={promptPWAInstall}>Install App</button>}
    </div>
  );
}

Usage in Vue 3

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import {
  registerServiceWorker,
  subscribeToPush,
  isPushSupported,
  onPWAInstallable,
  promptPWAInstall,
} from "pwa-notifications/client";

const canInstall = ref(false);
let cleanupInstallable = null;

onMounted(() => {
  registerServiceWorker("/sw.js");
  cleanupInstallable = onPWAInstallable((installable) => {
    canInstall.value = installable;
  });
});

onUnmounted(() => {
  if (cleanupInstallable) cleanupInstallable();
});

const handleSubscribe = async () => {
  if (!isPushSupported()) return alert("Push not supported!");
  const subscription = await subscribeToPush({
    vapidKey: import.meta.env.VITE_VAPID_PUBLIC_KEY,
  });
  // Send subscription to your backend
};
</script>

<template>
  <div>
    <button @click="handleSubscribe">Enable Notifications</button>
    <button v-if="canInstall" @click="promptPWAInstall">Install App</button>
  </div>
</template>

Server-Side API

Import from pwa-notifications/server to send push notifications from Node.js, Express, Next.js, or Nuxt:

import { sendPushNotification } from "pwa-notifications/server";

// Example payload structure
const subscription = {
  /* Retrieved from database */
};

await sendPushNotification(
  subscription,
  {
    title: "New Alert!",
    body: "You have a new message.",
    icon: "/icon-192x192.svg",
    url: "/",
  },
  {
    vapidPublicKey: process.env.VAPID_PUBLIC_KEY,
    vapidPrivateKey: process.env.VAPID_PRIVATE_KEY,
  },
);

Architecture Guide: Real-Time Hybrid Notification Pattern

For complex applications (like marketplaces or dashboard systems), developers often need real-time UI updates combined with OS-level PWA background push notifications.

A generic, highly efficient architecture is the Hybrid Database/Real-Time Sync Pattern:

  1. Database: Source of truth (Neon, Postgres, MySQL).
  2. Real-Time Trigger: Firestore, SSE, or Supabase. A counter is incremented when a notification is created.
  3. PWA Notifications: Registers service worker and subscriber endpoint.

React Hook Example:

import { useEffect, useState } from "react";
import {
  registerServiceWorker,
  subscribeToPush,
} from "pwa-notifications/client";
import { onSnapshot, doc } from "firebase/firestore"; // Or your preferred websocket listener

export function useNotifications(userId: string) {
  const [notifications, setNotifications] = useState([]);

  useEffect(() => {
    // 1. Register PWA Service Worker
    registerServiceWorker("/sw.js");

    // 2. Real-time trigger: refresh UI list when counter updates
    const unsubscribe = onSnapshot(doc(db, "users", userId), () => {
      // Fetch notifications from DB and update UI
    });

    return () => unsubscribe();
  }, [userId]);

  return { notifications };
}

Requirements

  • Browser with Service Worker Support
  • HTTPS (or localhost for development)
  • Node.js environment for sending notifications

License

MIT License

Author

Rey Mark Tapar

Website | GitHub