├── .gitignore ├── README.md ├── package.json └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | private.js 3 | node_modules 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ionic Push REST API via Node.js 2 | 3 | [![NPM version](http://img.shields.io/npm/v/ionic-push-server.svg)](https://www.npmjs.com/package/ionic-push-server) 4 | [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/benrondeau/Ionic-Push-Notification-NodeJS-Server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 5 | 6 | Node.js server using [Ionic Push REST API](https://ionicframework.com/docs/native/push/) to send push notifications on iOS and Android. 7 | 8 | # Requirements 9 | - [Node.js](https://nodejs.org/) 10 | - Ionic App that is [setup for push notifications](http://docs.ionic.io/docs/push-quick-start) 11 | 12 | # Example Usage: 13 | 14 | ```javascript 15 | var ionicPushServer = require('ionic-push-server'); 16 | 17 | var credentials = { 18 | IonicApplicationID : "myID", 19 | IonicApplicationAPItoken : "myIonicAPItoken" 20 | }; 21 | 22 | var notification = { 23 | "tokens": ["your", "device", "tokens"], 24 | "profile": "my-security-profile", 25 | "notification": { 26 | "title": "Hi", 27 | "message": "Hello world!", 28 | "android": { 29 | "title": "Hey", 30 | "message": "Hello Android!" 31 | }, 32 | "ios": { 33 | "title": "Howdy", 34 | "message": "Hello iOS!" 35 | } 36 | }; 37 | 38 | ionicPushServer(credentials, notification); 39 | 40 | ``` 41 | 42 | Problems? Join the discussion on [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/benrondeau/Ionic-Push-Notification-NodeJS-Server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) or file an [issue](https://github.com/benrondeau/Ionic-Push-Notification-NodeJS-Server/issues). Thanks! 43 | 44 | ## License 45 | [GNU General Public License v3](http://www.gnu.org/licenses/gpl-3.0.txt) 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-push-server", 3 | "version": "1.1.1", 4 | "description": "Ionic Push server using REST API", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/benrondeau/Ionic-Push-Notification-NodeJS-Server" 13 | }, 14 | "keywords": [ 15 | "API", 16 | "Ionic", 17 | "REST", 18 | "iOS", 19 | "push", 20 | "Android" 21 | ], 22 | "author": "Ben Rondeau, @_benrondeau", 23 | "license": "GNU General Public License v3", 24 | "bugs": { 25 | "url": "https://github.com/benrondeau/Ionic-Push-Notification-NodeJS-Server/issues" 26 | }, 27 | "homepage": "https://github.com/benrondeau/Ionic-Push-Notification-NodeJS-Server", 28 | "dependencies": { 29 | "querystring": "latest" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | // Dependencies 2 | var https = require('https'); 3 | var querystring = require('querystring'); 4 | 5 | // Push Notification Module 6 | module.exports = function (credentials, notification){ 7 | 8 | var postData = querystring.stringify(notification); 9 | 10 | var options = { 11 | hostname: 'api.ionic.io', 12 | path: '/push/notifications', 13 | method: 'POST', 14 | headers: { 15 | "Content-Type" : "application/json", 16 | "Authorization": "Bearer " + credentials.IonicApplicationAPItoken 17 | } 18 | }; 19 | 20 | var req = https.request(options, function(res) { 21 | console.log('STATUS: ' + res.statusCode); 22 | console.log('HEADERS: ' + JSON.stringify(res.headers)); 23 | res.setEncoding('utf8'); 24 | res.on('data', function (chunk) { 25 | console.log('BODY: ' + chunk); 26 | }); 27 | }); 28 | 29 | req.on('error', function(e) { 30 | console.log('problem with request: ' + e.message); 31 | }); 32 | 33 | req.write(JSON.stringify(notification)); 34 | req.end(); 35 | 36 | }; 37 | --------------------------------------------------------------------------------