Created
April 15, 2018 20:04
-
-
Save tklee1975/b2c37d7deb7e36783bb457d588005e83 to your computer and use it in GitHub Desktop.
an extremely simple NODE Server using HTTPS and HTTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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