Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 2.45 KB

README.md

File metadata and controls

42 lines (28 loc) · 2.45 KB

web-push

Web Push library for Node.js

Supports Firefox 43+ and Chromium/Chrome 42+. Notification with payloads are currently only supported in Firefox (see https://code.google.com/p/chromium/issues/detail?id=486040 for the status in Chromium).

NPM

Build Status dependencies devdependencies

sendNotification(endpoint, TTL, userPublicKey, payload)

Send a Push notification to an endpoint. userPublicKey and payload can be undefined, if you want to send a notification without a message.

  • endpoint is the endpoint URL;
  • TTL is a value in seconds that describes how long a push message is retained by the push service;
  • userPublicKey is the public key of the browser;
  • payload is the message to attach to the notification.

The function returns a Promise, resolved when the request to the push service is successful.

setGCMAPIKey(apiKey)

Sets the GCM API key that the library should use in making requests to GCM endpoints (in Chromium/Google Chrome).

  • apiKey is your GCM API key, you can obtain it from the Google Developer Console.

encrypt(userPublicKey, payload)

Encrypts the payload according to the Message Encryption for Web Push standard. (sendNotification will automatically encrypt the payload for you, so if you use sendNotification you don't need to worry about it).

  • userPublicKey is the public key of the browser;
  • payload is the message to attach to the notification.

Examples

The Service Worker Cookbook is full of Web Push examples using the web-push library.

Projects using web-push