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 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-apn

v1.0.23

Published

An easy, lightweight, adapter to send (APN) Apple Push Notifications.

Downloads

358

Readme

easy-apn

npm version Known Vulnerabilities

Why

Easy APN is a lightweight Node.js module designed for any version of Node, including Node.js 18 and later, allowing you to send push notifications to iOS devices using the Apple Push Notification Service (APNs) seamlessly. No dependencies are required as it leverages the simplicity and consistency of the curl (ships with Windows 10+) command for reliable error handling.

This module was born out of frustration after trying seemingly all existing APN npm libraries (apn-http2, apn2, node-apn, push-notification) in Node.js 18. When transitioning past Node.js 16 to Node.js 18, these modules returned error "unsupported" due to the introduction of native http2 in Node.js 18.

Easy APN aims to provide a simple and reliable solution for sending (possibly password protected) .p12 or .pem files using system features, which Apple seems to prefer. Let me know if this fixed your problem, too. Open to feature and pull requests.

Installation

You can install the easy-apn module via npm:

npm install easy-apn

Usage

const sendPushNotification = require('easy-apn');

const pushNotificationData = {
  title: 'Your Notification Title', // optional
  message: 'Your Notification Message',//*required
  sound: 'default',            // optional
  badge: 1,                    // optional
  certPath: '/full/path/to/your/cert.p12' || '/full/path/to/your/cert.pem', //*required
  exportPassword: 'your-export-password', //*required if p12, or if PEM begins with BEGIN ENCRYPTED PRIVATE KEY
  appBundleId: 'com.your.app', //*required
  pushToken: 'your-device-push-token', //*required
  additionalInfo: 'Test',      // optional
  production: true,            // optional, use false for sandbox.push.apple.com must be dev certs 
  debuggerEnabled: true        // optional, verbose logs  
};

async function simpleSend() {
    const err = await sendPushNotification(pushNotificationData)
    if(err){console.log(err)}
}
simpleSend()

async function bulkSend() {
  for (let index = 0; index < 1000; index++) {
    pushNotificationData.badge = index
    const err = await sendPushNotification(pushNotificationData)
    if(err){console.log(err)}
  }
}
// bulkSend()

API

  • sendPushNotification(options, callback)
    • Sends a push notification to an iOS device using APNs.

    • options (Object): An object containing the following properties:

      • [title] (String): The title of the push notification (required).
      • [message] (String): The message content of the push notification (required).
      • [sound] (String, optional): The name of the sound to be played (default: 'default').
      • [badge] (Number, optional): The badge number to display (default: 0).
      • [certPath] (String): The file path to your P12 certificate file (required).
      • [exportPassword] (String): The export password for the P12 certificate file (required).
      • [appBundleId] (String): The bundle ID of your iOS app (required).
      • [pushToken] (String): The device's push notification token (required).
      • [additionalInfo] (String, optional): Additional information for the push notification (default: '').
      • [production] (Boolean, optional): Whether to send the notification to the production environment (true) or the sandbox environment (false, default).
      • [debuggerEnabled] (Boolean, optional) Prints stdout and stderr stream.
    • callback (Function): A callback function to handle the result of sending the push notification. It will be called with an error as the first argument if there is an error, or null if the push notification was sent successfully.