express 4.x redirect http to https

I have the following code :

var https        = require('https');
var http         = require('http');
var express      = require('express');
var app          = express();
var router       = express.Router();

app.use('/', router);

//have 'server' listen for https
var server = https.createServer(config.sslCredential, app);

//listen server on http, and always redirect to https
var httpServer = http.createServer(function(req,res){

but somehow I can’t get the https request to be redirected into https request, how should I do this correctly on node.js with express 4.x ?

27 thoughts on “express 4.x redirect http to https”

Leave a Comment