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

apn-legacy

v2.1.5

Published

An interface to the Apple Push Notification service for old versions of Node.js

Downloads

50

Readme

node-apn

A Node.js module for interfacing with the Apple Push Notification service.

Maintenance help wanted Build status Code coverage Codacy dependencies devdependencies

Features

  • Based on HTTP/2 based provider API
  • Maintains a connection to the server to maximise notification batching and throughput.
  • Automatically resends unsent notifications if an error occurs

Installation

npm is the preferred installation method:

$ npm install apn --save

Quick Start

This readme is a brief introduction, please refer to the full documentation in doc/ for more details.

If you have previously used v1.x and wish to learn more about what's changed in v2.0, please see What's New

Load in the module

var apn = require('apn');

Connecting

Create a new connection to the Apple Push Notification provider API, passing a dictionary of options to the constructor. You must supply your token credentials in the options.

var options = {
  token: {
    key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
    keyId: "key-id",
    teamId: "developer-team-id"
  },
  production: false
};

var apnProvider = new apn.Provider(options);

By default, the provider will connect to the sandbox unless the environment variable NODE_ENV=production is set.

For more information about configuration options consult the provider documentation.

Help with preparing the key and certificate files for connection can be found in the wiki

Sending a notification

To send a notification you will first need a device token from your app as a string

let deviceToken = "a9d0ed10e9cfd022a61cb08753f49c5a0b0dfb383697bf9f9d750a1003da19c7"

Create a notification object, configuring it with the relevant parameters (See the notification documentation for more details.)

var note = new apn.Notification();

note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload = {'messageFrom': 'John Appleseed'};
note.topic = "<your-app-bundle-id>";

Send the notification to the API with send, which returns a promise.

apnProvider.send(note, deviceToken).then( (result) => {
  // see documentation for an explanation of result
});

This will result in the the following notification payload being sent to the device

{"messageFrom":"John Appelseed","aps":{"badge":3,"sound":"ping.aiff","alert":"\uD83D\uDCE7 \u2709 You have a new message"}}

You should only create one Provider per-process for each certificate/key pair you have. You do not need to create a new Provider for each notification. If you are only sending notifications to one app then there is no need for more than one Provider.

If you are constantly creating Provider instances in your app, make sure to call Provider.shutdown() when you are done with each provider to release its resources and memory.

Troubleshooting

You are encouraged to read the extremely informative Troubleshooting Push Notifications Tech Note in the first instance, in case your query is answered there.

Support

If you have any questions or difficulties working with the module, the node-apn Google group should be your first port of call.

Please include as much detail as possible - especially debug logs. If the problem is reproducible, sample code is also extremely helpful. GitHub Issues should only be created for verified problems and enhancements, this will allow them to be tracked more easily.

Resources

Credits

Created by Andrew Naylor

Thanks to: Ian Babrou, dgthistle, Keith Larsen, Mike P, Greg Bergé, Asad ur Rehman, Nebojsa Sabovic, Alberto Gimeno, Randall Tombaugh, Michael Stewart, Olivier Louvignes, porsager, Craig Hockenberry

License

Released under the MIT License

Copyright (c) 2013 Andrew Naylor

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.