Rss Feed Tweeter button Facebook button Technorati button Reddit button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button

A Waage Blog

Ruby, Rails, Life

Archive for the ‘Node.js’ Category

Install Comodo PositiveSSL Certificate with Node.js

with 5 comments

So today I tried to install the cheap Comodo PositiveSSL certificate to use on my Node.js / express.js server. Unfortunately, all the documentation and examples of installing an SSL certificate on a Node.js server only mention two options in the createServer() method (See my full example here) :

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

var https_options = {
  key: fs.readFileSync("/path/to/server.key"),
  cert: fs.readFileSync("/path/to/mydomain.crt")
var https_server = https.createServer(https_options);

However, with the PositiveSSL certificate, Comodo will actually send you 3 files:
1) PositiveSSLCA2.crt
2) AddTrustExternalCARoot.crt
3) mydomain.crt

This is quite confusing for someone who doesn’t really understand (nor want to understand) all the details of how an SSL certificate works. Which one do I use for the cert: option??

Naturally, I started with the mydomain.crt file. This led to a cryptic web browser error message:
“this certificate was signed by an unknown authority”

So, a bit of googling found that when installing the PositiveSSL cert on Apache servers, you must use a chain file (mod_ssl option: SSLCertificateChainFile). If you check the Apache mod_ssl documentation you will see that this file is a concatenation of certificate files:

“Such a file is simply the concatenation of the various PEM-encoded CA Certificate files, usually in certificate chain order.”

So, what you have to do is the following:
1) Create a “bundle” file by concatenating the PositiveSSLCA2 and AddTrustExternalCARoot certificates

cat PositiveSSLCA2.crt AddTrustExternalCARoot.crt >

2) Add this certificate as the “ca” option when creating your Node.js sever:

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

var https_options = {
  ca: fs.readFileSync("/path/to/"),
  key: fs.readFileSync("/path/to/server.key"),
  cert: fs.readFileSync("/path/to/mydomain.crt")
var https_server = https.createServer(https_options);

This should properly set up the CA chain so that browsers can verify the SSL certificate.

Written by Andrew Waage

March 4th, 2012 at 5:42 pm

Node.js and RESTify Server with both HTTP and HTTPS

with 4 comments

Here’s a quick guide on setting up a Node.js server using the restify module that accepts BOTH http and https connections.

We want to re-use as much code as possible because the two servers (HTTP and HTTPS) are identical besides the protocol.

In the example, we created a self-signed SSL certificate. If you need help on that, check out this quick guide on how to set up a self-signed SSL certificate on Ubuntu.

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

// Setup some https server options
var https_options = {
  key: fs.readFileSync('/etc/ssl/self-signed/server.key'),
  certificate: fs.readFileSync('/etc/ssl/self-signed/server.crt')

// Instantiate our two servers
var server = restify.createServer();
var https_server = restify.createServer(https_options);

// Put any routing, response, etc. logic here. This allows us to define these functions
// only once, and it will be re-used on both the HTTP and HTTPs servers
var setup_server = function(app) {
        function respond(req, res, next) {
           res.send('I see you ' +;

        // Routes
        app.get('/test/:name', respond);

// Now, setup both servers in one step

// Start our servers to listen on the appropriate ports
server.listen(80, function() {
  console.log('%s listening at %s',, server.url);

https_server.listen(443, function() {
  console.log('%s listening at %s',, https_server.url);

Written by Andrew Waage

February 27th, 2012 at 4:05 pm

Posted in Node.js

How to install Node.js on Ubuntu – in under 5 minutes

with 9 comments

Follow along, as we create our first Node.js app using the “express” framework in under 5 minutes!
Note: We’re on Ubuntu 10.04 LTS (as root!)

# Update the system and install some necessary packages

$ apt-get update
$ apt-get install g++ curl libssl-dev apache2-utils
$ apt-get install git-core

# Find the latest package to install at (example uses 0.6.11)

$ wget
$ tar xzf node-v0.6.11.tar.gz
$ cd node-v0.6.11
$ ./configure
$ make
$ make install

# Install npm (Node.js package manager)

$ cd /usr/local/src
$ git clone
$ cd npm/
$ make install

# Install express framework, -g flag installs the express executable globally

$ npm install -g express

# Create an app with the express framework

$ express /var/www/foo
$ cd /var/www/foo/

# Install dependencies

$ npm install -d

# Start the node app!

$ node app.js

Voila! I told you it was fast :)

Written by Andrew Waage

February 23rd, 2012 at 10:35 pm

Posted in Node.js

Tagged with , , ,