Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web-push

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web-push

Web Push library for Node.js

  • 3.6.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
139K
decreased by-13.74%
Maintainers
1
Weekly downloads
 
Created

What is web-push?

The web-push npm package is a Node.js library that allows you to send push notifications to web applications. It implements the Web Push Protocol and is commonly used to send notifications to users' browsers.

What are web-push's main functionalities?

Generate VAPID keys

This feature allows you to generate VAPID (Voluntary Application Server Identification) keys, which are used to authenticate your server with the push service.

const webpush = require('web-push');
const vapidKeys = webpush.generateVAPIDKeys();
console.log(vapidKeys);

Set VAPID details

This feature allows you to set the VAPID details, including the contact email and the public and private VAPID keys, which are necessary for sending authenticated push notifications.

const webpush = require('web-push');
webpush.setVapidDetails(
  'mailto:example@yourdomain.org',
  'YOUR_PUBLIC_VAPID_KEY',
  'YOUR_PRIVATE_VAPID_KEY'
);

Send a push notification

This feature allows you to send a push notification to a subscribed client. You need to provide the subscription object and the payload you want to send.

const webpush = require('web-push');
const subscription = {
  endpoint: 'https://fcm.googleapis.com/fcm/send/abc123',
  keys: {
    p256dh: 'YOUR_P256DH_KEY',
    auth: 'YOUR_AUTH_KEY'
  }
};
const payload = JSON.stringify({ title: 'Hello', body: 'World' });
webpush.sendNotification(subscription, payload)
  .then(response => console.log('Sent:', response))
  .catch(error => console.error('Error:', error));

Other packages similar to web-push

Keywords

FAQs

Package last updated on 16 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc