I need your help for my upcoming conference talk

Are you LOOKING for a job in IoT? or Are you already WORKING in IoT?

Click one of the links below to fill out a one question survey.

Thank you, Chris

Yes! I'm Looking Yes! I'm Working

Using HTTPS with express is almost as simple as replacing require('http') with require('https'). For my application I am using a self-signed certificate that I created after following the directions on Nate Good’s blog. I placed the certs in a folder called cert.

I initialized the variables in preparation for two servers following this Stackoverflow question. One server for https listening on 443 and another for http listening on port 80. Then I wrote the http server to forward all requests to the https server. So that node doesn’t run as root I edited the iptables to map port 80 to 8081 and port 443 to 8080.

var app = express()
  , httpapp = express()
  , fs = require('fs')  
  , options = {
    key: fs.readFileSync('./cert/client.key'),
    cert: fs.readFileSync('./cert/client.crt'),
    requestCert: true
  , http = require('http').createServer(httpapp)
  , server = require('https').createServer(options, app)  
  , io = require('socket.io').listen(server);

The following code forwards all requests for HTTP to HTTPS.



Then on the client side I had to setup socket.io to use the secured port as well.

var socket = io.connect('', {secure: true});

The process was first to obtain or create an SSL Certificate. Then create an express server that requires ‘HTTPS’. Finally, setup the client JavaScript to reply on the HTTPS secure port.

EDIT 7/24/13: Also check out the documentation for HTTPS.

Chris Larson

September is my birthday month. This year I'm doing something special for myself. I'm giving my future 40 year old self a birthday present.

chrylarson chrylarson