Skip to content

feathers-webpush

feathers-webpush module provides a simplified way to send web push notifications in a FeathersJS application.

Principle

It leverages the web-push package to interact with the Web Push protocol.

webpush-principle

Installation

Install with your preferred package manager:

shell
pnpm add @kalisio/feathers-webpush
shell
npm install @kalisio/feathers-webpush
shell
yarn add @kalisio/feathers-webpush

Configuration

To configure feathers-webpush in your FeathersJS application, you need to set up both the server and the client parts.

Server-side configuration

  1. Generate VAPID keys (using the web-push CLI):
bash
pnpm web-push generate-vapid-keys --json
  1. Add the service to your Feathers app:
js
import { Service } from 'feathers-webpush/server'

const vapidDetails = {
  subject: process.env.VAPID_SUBJECT,    // e.g., 'mailto:admin@example.com'
  publicKey: process.env.VAPID_PUBLIC_KEY,
  privateKey: process.env.VAPID_PRIVATE_KEY
}

app.use('push', new Service({ vapidDetails, app }), {
  methods: ['create']
})

This sets up a service that can send web push notifications and handle subscription delivery results.

Client-side configuration

On the client, you need to:

  • Register a service worker
  • Request notification permission from the user
  • Subscribe to push notifications using the server’s public VAPID key
js
import { registerServiceWorker, requestNotificationPermission, subscribePushNotifications } from 'feathers-webpush/client'

await registerServiceWorker()
await requestNotificationPermission()
const subscription = await subscribePushNotifications(publicVapidKey)

Example

For a complete example, see the feathers-webpush example in this repository.