user1379417
user1379417

Reputation:

NodeJS APN module cannot find certificate file on Ubuntu

I am using the apn module (https://github.com/argon/node-apn) to send push notifications to iPhones from NodeJS.

My code works fine on my development machine (Mac OSX) and is successfully pushing notifications through the Apple sandbox gateway (gateway.sandbox.push.apple.com), but when I move it to the staging server (which is running Ubuntu) pushing notifications fails with the message:

 Error: ENOENT, no such file or directory 'apns-dev-cert.pem'

I am setting up the NodeJS apn object as such:

var options = {
    cert: "apns-dev-cert.pem",          
    key:  "apns-key.pem",               
    passphrase: null,   
    gateway: "gateway.sandbox.push.apple.com",              
    port: 2195,                         
    enhanced: true,                     
    errorCallback: undefined,                       
    cacheLength: 5                                  
};

On my development Mac OSX machine, the cert is installed in the Keychain. From my limited understanding of Ubuntu, the equivalent would be to copy the cert file to /etc/ssl/certs. I tried doing this, and also changing the path to "/etc/ssl/certs/apn-dev-cert.pem" in my NodeJS code, but the same error message shows up.

Any ideas?

Upvotes: 1

Views: 4293

Answers (2)

You try to setup as below:

var options = {
    //cert: "apns-dev-cert.pem",          
    //key:  "apns-key.pem",               
    pfx: '<path>/apns-key.pem',    
    passphrase: null,   
    gateway: "gateway.sandbox.push.apple.com",              
    port: 2195,                         
    enhanced: true,                     
    errorCallback: undefined,                       
    cacheLength: 5                                  
};

Upvotes: 0

Kristofer Sommestad
Kristofer Sommestad

Reputation: 3061

I struggled a lot with this issue until I realized that I hadn't understood how the fs module reads files. Apparently, it reads them from the directory where you started your node process. So the path to your .pem files should be relative to wherever you're doing that.

You might wanna check out __dirname too, which might make it easier to specify your paths.

Upvotes: 3

Related Questions