Skip to content

Instantly share code, notes, and snippets.

@baniol
Created June 18, 2014 07:36
Show Gist options
  • Save baniol/ea8d2f788e351dc55d2a to your computer and use it in GitHub Desktop.
Save baniol/ea8d2f788e351dc55d2a to your computer and use it in GitHub Desktop.
nodejs ssl certificate
// from: http://www.hacksparrow.com/node-js-https-ssl-certificate.html
$ openssl genrsa -out hacksparrow-key.pem 1024
$ openssl req -new -key hacksparrow-key.pem -out certrequest.csr
... bunch of prompts
$ openssl x509 -req -in certrequest.csr -signkey hacksparrow-key.pem -out hacksparrow-cert.pem
var https = require('https');
var fs = require('fs');
var hskey = fs.readFileSync('hacksparrow-key.pem');
var hscert = fs.readFileSync('hacksparrow-cert.pem')
var options = {
key: hskey,
cert: hscert
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("Hi from HTTPS");
}).listen(8000);
// Express
var fs = require('fs');
var hskey = fs.readFileSync('hacksparrow-key.pem');
var hscert = fs.readFileSync('hacksparrow-cert.pem')
var options = {
key: hskey,
cert: hscert
};
var app = require('express').createServer(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment