A basic Node.js REST API built with Express for registering devices and sending push notifications with Pushy.
Pushy is the most reliable push notification gateway, perfect for real-time, mission-critical applications.
This API utilizes in-memory persistence to make things simple, but be aware that restarting the server will clear the registered devices list. Feel free to modify the persistence layer to utilize a real database, such as MongoDB.
Clone the repository locally and install its dependencies:
git clone https://github.com/pushy-me/pushy-node-backend.git
cd pushy-node-backend
npm install
Open config.js
and insert your app's Secret API Key, available in the Dashboard:
pushy: {
// Secret API Key
secretApiKey: 'n00d4eea4f16btddd6d44fcfb72f2bbc20b8032175fdc979ada24a5d02b'
}
Start the server up:
npm start
Note: All requests are
GET
requests to make it easy to execute them from a web browser for testing.
Returns a list of registered devices.
Register a device for notifications. Execute this request from your mobile app, replacing :token
with the actual device token.
Send a test notification to all registered devices, with the following payload:
{"message": "Hello World!"}
This request will throw an error if no devices have been registered yet, or if the Secret API Key is invalid:
{"error": "We could not find an app with the specified API key. Please contact us at support@pushy.me."}
To actually use this in production, consider the following:
-
Modify the push payload with data specific to your application
-
Modify the persistence layer to utilize a real database, such as MongoDB
-
Modify the
/push
endpoint to only send notifications to specific devices, based on app-specific criteria