Generating APN certificates for node.js app

Generating APN certificates for node.js app

Marcell Simon
Marcell Simon

To get a certificate from Apple, you have to do a lot of steps. A great tutorial for these steps can be found here: Generate APNS certificate for iOS Push

Open the downloaded .cer file with Keychain and export it in .p12. (push_dev.p12 / push_prod.p12)

The final .cer and .p12 file is named push_dev or push_prod here.

Move them to a folder and open a Terminal in that folder.

Generate development .pem files

openssl x509 -in push_dev.cer -inform DER -outform PEM -out dev_cert.pem
openssl pkcs12 -in push_dev.p12 -out dev_key.pem -nodes

Generate production .pem files

openssl x509 -in push_prod.cer -inform DER -outform PEM -out prod_cert.pem
openssl pkcs12 -in push_prod.p12 -out prod_key.pem -nodes

The output will be: dev_cert.pem, dev_key.pem / prod_cert.pem, prod_key.pem

You can use these files for the APN config.

const options = {
    production: false,
    cert: "/opt/certificates/dev_cert.pem",
    key: "/opt/certificates/dev_key.pem"

const service = new apn.Provider(options)

const note = new apn.Notification()
note.topic = ""
note.alert = "Hello!"

await service.send(note, deviceTokens)

Join the conversation.