Skip to content

Instantly share code, notes, and snippets.

@re5et
Created July 1, 2013 19:34
Show Gist options
  • Save re5et/5903832 to your computer and use it in GitHub Desktop.
Save re5et/5903832 to your computer and use it in GitHub Desktop.
node https server
const crypto = require('crypto'),
fs = require("fs"),
http = require("http");
var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();
var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
var handler = function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
};
var server = http.createServer();
server.setSecure(credentials);
server.addListener("request", handler);
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment