2020年2月11日 星期二

NodeJS Express with HTTPS on Windows 10


https://timonweb.com/posts/running-expressjs-server-over-https/

1. Install
Install Win64OpenSSL_Light-1_1_1d.exe with all default values
http://slproweb.com/products/Win32OpenSSL.html
Win64 OpenSSL v1.1.1d Light (EXE) 3MB
http://slproweb.com/download/Win64OpenSSL_Light-1_1_1d.exe

2. Create

Go to a new folder, run

"C:\Program Files\OpenSSL-Win64\bin\openssl.exe" req -nodes -new -x509 -keyout server.key -out server.cert

This gives

server.cert
server.key


3. main.js code

var opn = require('opn');
opn('https://127.0.0.1:8081/');

var fs = require('fs');
var https = require('https');

var express = require('express');
var app = express();

app.get('/', function (req, res) {
   res.send('Hello World');
});

var server = https.createServer({
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.cert')
}, app).listen(8081, function () {
   var host = server.address().address;
   var port = server.address().port;
   
   console.log("Example app listening at http://%s:%s", host, port);

});




End




沒有留言:

張貼留言

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...