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

pushy

v4.0.1

Published

The official Node.js package for sending push notifications with Pushy.

Downloads

12,572

Readme

pushy-node

npm version

The official Node.js package for sending push notifications with Pushy.

Pushy is the most reliable push notification gateway, perfect for real-time, mission-critical applications.

Note: If you don't have an existing Node.js project, consider using our Node.js backend API sample project as a starting point to make things easier for you.

Usage

First, install the package using npm:

npm install pushy --save

Then, use the following code to send a push notification to target devices using the Send Notifications API:

var Pushy = require('pushy');

// Plug in your Secret API Key
// Get it from the Pushy Dashboard: https://dashboard.pushy.me/apps
var pushy = new Pushy('SECRET_API_KEY');

// Set push payload data to deliver to device(s)
var data = {
    message: 'Hello World!'
};

// Insert target device token(s), or set to Pub/Sub topic
var to = ['DEVICE_TOKEN'];

// Set optional push notification options (such as iOS notification fields)
var options = {
    notification: {
        badge: 1,
        sound: 'ping.aiff',
        body: 'Hello World \u270c'
    },
};

// Send push notification using the Send Notifications API
pushy.sendPushNotification(data, to, options, function (err, result) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }
    
    // Log success
    console.log('Push sent successfully! (ID: ' + result.id + ')');
});

Note: Make sure to replace SECRET_API_KEY with your app's Secret API Key, available in the Pushy Dashboard (Click your app -> API Authentication tab).


The library also supports using promise syntax instead of callbacks for all API methods:

pushy.sendPushNotification(data, tokens, options)
    .then(function (result) {
        // Log success
        console.log('Push sent successfully! (ID: ' + result.id + ')');
    }).catch(function (err) {
        // Log errors to console
        return console.error(err);
    });

Push APIs

pushy.sendPushNotification(data, to, options)

Instantly send push notifications to your users using the Send Notifications API (see example above):

pushy.sendPushNotification(data, to, options, function (err, result) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }
    
    // Log success
    console.log('Push sent successfully! (ID: ' + result.id + ')');
});

pushy.getNotificationStatus(pushId)

Check the delivery status of your push notifications using the Notification Status API:

pushy.getNotificationStatus('PUSH_ID', function (err, status) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log notification status
    console.log('Notification Status: ', JSON.stringify(status, null, 2));
});

pushy.deletePushNotification(pushId)

Permanently delete a pending notification using the Notification Deletion API:

pushy.deletePushNotification('PUSH_ID', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Pending notification deleted successfully');
});

Device APIs

pushy.getDeviceInfo(deviceToken)

Fetch device info, presence, undelivered notifications, and more by device token using the Device Info API:

pushy.getDeviceInfo('DEVICE_TOKEN', function (err, deviceInfo) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log device info
    console.log('Device Info: ', JSON.stringify(deviceInfo, null, 2));
});

pushy.getDevicePresence(deviceTokens)

Check the presence and connectivity status of multiple devices using the Device Presence API:

pushy.getDevicePresence(['DEVICE_TOKEN', 'DEVICE_TOKEN_2'], function (err, devicePresence) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log device presence array
    console.log('Device Presence: ', JSON.stringify(devicePresence, null, 2));
});

Pub/Sub APIs

pushy.getTopics()

Retrieve a list of your app's topics and subscribers count using the Pub/Sub Topics API:

pushy.getTopics(function (err, topics) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log subscribed topics
    console.log('Subscribed topics: \n' + JSON.stringify(topics, null, 2));
});

pushy.getSubscribers(topic)

Retrieve a list of devices subscribed to a certain topic using the Pub/Sub Subscribers API:

pushy.getSubscribers('news', function (err, subscribers) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log subscribed devices
    console.log('Devices subscribed to topic: \n' + JSON.stringify(subscribers, null, 2));
});

pushy.subscribe(topics, deviceToken)

Subscribe a device to one or more topics using the Pub/Sub Subscribe API:

pushy.subscribe(['news', 'weather'], 'DEVICE_TOKEN', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Subscribed device to topic(s) successfully');
});

pushy.unsubscribe(topics, deviceToken)

Unsubscribe a device from one or more topics using the Pub/Sub Unsubscribe API

pushy.unsubscribe(['news', 'weather'], 'DEVICE_TOKEN', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Unsubscribed device from topic(s) successfully');
});

License

Apache 2.0