A minimal Express + Service Worker project that supports:
- Persistent VAPID keys via environment variables.
- Background push delivery (works with tab closed/minimized after subscription).
- Subscription persistence in
subscriptions.json.
npm install
node scripts/generate-vapid-keys.jsCopy .env.example to .env and paste generated values.
You can configure keys either way:
- Separate env vars:
VAPID_PUBLIC_KEY=...
VAPID_PRIVATE_KEY=...- Single env var:
VAPID_KEYS={"publicKey":"...","privateKey":"..."}or:
VAPID_KEYS=publicKey:privateKeyAt startup, the server logs:
- key source
VAPID_PUBLIC_KEYVAPID_PRIVATE_KEY
npm startOpen http://localhost:3000, click Enable notifications, then use Send push batch.
GET /api/config-> public VAPID key and sending limits.POST /api/subscribe-> save/update browser subscription.POST /api/send-> send repeated push messages.