Skip to content

Instantly share code, notes, and snippets.

@edbo
Created January 19, 2011 04:42
Show Gist options
  • Save edbo/785696 to your computer and use it in GitHub Desktop.
Save edbo/785696 to your computer and use it in GitHub Desktop.
Snippet demonstrating how to use Node as an https server
var crypto = require('crypto'),
fs = require('fs'),
http = require('http');
var port = 8080;
var privateKey = fs.readFileSync('privatekey.pem').toString(),
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("");
};
var server = http.createServer();
server.setSecure(credentials);
server.addListener("request", handler);
server.listen(port);
console.log("Listening on port: " + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment