Skip to content

Instantly share code, notes, and snippets.

@xiaoysh8
Created October 12, 2019 03:53
Show Gist options
  • Save xiaoysh8/b23e1edc4d4177eee31dc8250110cb61 to your computer and use it in GitHub Desktop.
Save xiaoysh8/b23e1edc4d4177eee31dc8250110cb61 to your computer and use it in GitHub Desktop.
node express https
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
const express = require('express');
const https = require('https');
const fs = require('fs');
const port = 3000;
var key = fs.readFileSync(__dirname + '/../certs/selfsigned.key');
var cert = fs.readFileSync(__dirname + '/../certs/selfsigned.crt');
var options = {
key: key,
cert: cert
};
app = express()
app.get('/', (req, res) => {
res.send('Now using https..');
});
var server = https.createServer(options, app);
server.listen(port, () => {
console.log("server starting on port : " + port)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment