node-apn : Provider should be created per notification request or one-time

383 views Asked by At

I am new to node-apn. I have implemented it in nodejs application. Below is my code.

var APN = require('apn')
var apnProvider = new APN.Provider({
    token: {
        key: "PATH_TO_FILE",
        keyId: "KEY",
        teamId: "TEAM"
    },
    production: false
});

module.exports = {
    send: function (tokens, message, callBackFn) {

        var note = new APN.Notification({
            alert: "Breaking News: I just sent my first Push Notification",
        });

        // The topic is usually the bundle identifier of your application.
        note.topic = "BUNDLE";

        console.log(`Sending: ${note.compile()} to ${tokens}`);
        service.send(note, tokens).then(callBackFn);
    }
};

So in some documentation it says we should shutdown apnProvider.

So my question is should i create apnProvider globally (like i have done)?

OR should i create per send request (inside send function) & call shutdown after send notification.

I tried reading online. But i couldn't find any example like my requirements.

0

There are 0 answers