Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created April 15, 2018 20:04
Show Gist options
  • Select an option

  • Save tklee1975/b2c37d7deb7e36783bb457d588005e83 to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/b2c37d7deb7e36783bb457d588005e83 to your computer and use it in GitHub Desktop.
an extremely simple NODE Server using HTTPS and HTTP
const http = require("http");
http.createServer((req, res) => {
res.writeHead(200);
res.end("<html><p>Hello HTTP!! <br/>Greeting from Kencoder!</p></html>\n");
}).listen(8000);
// use 'npm install express --save' to install express
var express = require('express');
var fs = require('fs');
const https = require("https");
// note: the key and cert need to be generated before
const options = {
key: fs.readFileSync("./keys/kencoder.com.key.pem"),
cert: fs.readFileSync("./keys/kencoder.com.cert.pem"),
passphrase : "123456"
};
const app = express();
app.use((req, res) => {
res.writeHead(200);
res.end("<html><p>Hello HTTPS!! <br/>Greeting from Kencoder!</p></html>\n");
});
app.listen(8000);
https.createServer(options, app).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment