Posted By Himanshu Goyal | 14-Mar-2016

IntroFor sending push notification we have to use apn npm module .There is one more module in nodejs ie. apns but according to my experience that module had some bugs.

APNS (Apple Push Notification Server) is third parity server of apple which we used .Every device had a unique device token and during time of signup that device token is saved in db and this device token is used to send push notification. A p12 file is created by apple site and it is used in our apn module opition .


1. Install npm 

 npm install apn

2.Requried npm

var apn = require('apn');

3.Make the object of connection

var options = { };

var apnConnection = new apn.Connection(options);

4.Create  the device Object and put the hexadecimal device token in device object

var myDevice = new apn.Device(token);

5.Create the notification object to set the other setting like sound ,message ,expire time,badge etc

var notificationObject = new apn.Notification();

notificationObject.alert=message //which you want to send on mobile screen

notificationObject.payload={} //any other data which you want to sent to mobile side for provide other information

6.Set the notification object and send to device using this method:

apnConnection.pushNotification(notificationObject, myDeviceObject);

 Set the various option in apns :

a)pfx:here we set the path of p12 file 

b)cert:here we set the path of cert.pem

c)key: here we set the path of key.pem

d)passphrase:here we set the password of certificates

e)gateway:here we put the url of gateway because there are two enviorement one is for production and second for development

f)production: true/false if we use production environment then set to be true otherwise it is false for development
Request for Proposal

Recaptcha is required.

Sending message..