- Home
- Documentation
- Client Setup
- iOS
- Create App
- Get the SDK
- Enable Capability
- Register Devices
- Handle Notifications
- Subscribe to Topics
- Setup APNs Authentication
- Send Test Notification
- Android
- Create App
- Get the SDK
- Register Devices
- Modify Launcher Activity
- Modify AndroidManifest
- Setup BroadcastReceiver
- Parse Notification Data
- Subscribe to Topics
- Send Test Notification
- Web Push
- Create App
- Get the SDK
- Register Visitors
- Handle Notifications
- Subscribe to Topics
- Send Test Notification
- Additional Platforms
- Ionic
- Flutter
- Python
- macOS
- Angular
- Electron
- Cordova
- Capacitor
- PhoneGap
- React Native
- MAUI (Android)
- Xamarin (Android)
- Migration Guides
- Backend Setup
-
API Reference - SDK Reference
- Additional Resources
Got Feedback?
We'd love to hear what you have to say about our documentation. Let us know how we can improve it.
Node.js Backend Sample
Send push notifications to your users with our official Node.js package.
Note: If you don't have an existing Node.js project, consider using our sample Node.js backend project as a starting point to make things easier.
Install the pushy
package in your existing project:
npm install pushy --save
Then, use the following sample code to send a push notification to target devices:
var Pushy = require('pushy');
// Plug in your Secret API Key
// Get it here: https://dashboard.pushy.me/
var pushyAPI = new Pushy('SECRET_API_KEY');
// Set push payload data to deliver to device(s)
var data = {
message: 'Hello World!'
};
// Insert target device token(s) here
var to = ['DEVICE_TOKEN'];
// Optionally, send to a publish/subscribe topic instead
// to = '/topics/news';
// Set optional push notification options (such as iOS notification fields)
var options = {
notification: {
badge: 1,
sound: 'ping.aiff',
title: 'Test Notification',
body: 'Hello World \u270c',
},
};
// Send push notification via the Send Notifications API
// https://pushy.me/docs/api/send-notifications
pushyAPI.sendPushNotification(data, to, options, function (err, id) {
// Log errors to console
if (err) {
return console.log('Fatal Error', err);
}
// Log success
console.log('Push sent successfully! (ID: ' + 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). This is a backend API endpoint. Never expose your application's Secret API Key in your client code.