Skip to content

Instantly share code, notes, and snippets.

@cookie-ag
Created October 4, 2016 06:04
Show Gist options
  • Save cookie-ag/de29b4d056c54b30a0d8211e9afdb93a to your computer and use it in GitHub Desktop.
Save cookie-ag/de29b4d056c54b30a0d8211e9afdb93a to your computer and use it in GitHub Desktop.
Simple HTTPS express 4.x server
// Create self-signed certificate using $ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
// Key is certificate key and cert.pem is certificate file
var fs = require('fs'),
https = require('https'),
express = require('express'),
app = express();
https.createServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}, app).listen(55555);
app.get('/', function (req, res) {
res.header('Content-type', 'text/html');
return res.end('<h1>Hello, Secure World!</h1>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment