I'm using .pfx certification in my node.js https server and I can't use 'passphrase' in option

Jack O'Neill picture Jack O'Neill · Feb 6, 2015 · Viewed 16.8k times · Source

I'm currently making an web application with node.js and https. So I try to use my .pfx(I got the file from here http://www.cert-depot.com/) for certification required for https, like following code:

var https = require('https');
var fs = require('fs');

var options = {
    pfx: fs.readFileSync('./8ab20f7b-51b9-4c09-a2e0-1918bb9fb37f.pfx')
    passphrase: 'password'
};

var server = https.createServer(options, function (request, response) {
    fs.readFile('index.html', function (error, data) {
        response.writeHead(200, {'Content-Type': 'text/html'});
        response.end(data);
    });
}).listen(12345, function(){
    console.log('server running');
});

But when I start this code with node.js, I'm getting an error message in my windows console:

passphrase: 'password'

Unexpected identifier

My code is very similar to the official guide page of Node.js (http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener), but I can't start my https server.

What's wrong with my passphrase? (I'm running node.js in Windows 8 64bit.)

Answer

Ahmad AL-ansari picture Ahmad AL-ansari · Feb 12, 2015

I guess the missing comma between your pfx and passphrase properties is what cause the error. Here I added the comma:

var options = {
    pfx: fs.readFileSync('./8ab20f7b-51b9-4c09-a2e0-1918bb9fb37f.pfx'),
    passphrase: 'password'
};