1

I have a certificate and key, and I'm looking to serve my pages over https. How do I configure nodejs/expressjs to do so?

I'm explicitly looking to do this through the expressjs library.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
blueberryfields
  • 45,910
  • 28
  • 89
  • 168

1 Answers1

3

if you use 0.2.4. you can use

var express = require('express');
var fs = require("fs");
var crypto = require('crypto');

var app = express.createServer();
var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();
var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
app.setSecure(credentials);

but this not possible if you use node 0.4, as you can't call setSecure() to convert a server as SSL. One must create an instance of https.Server.

i don't know if there are any future plan to support this

amira
  • 58
  • 3
  • express now supporting creating an HTTPS server var app = require('express').createServer({ key: ... }); – amira Mar 20 '11 at 06:53