记一下nodejs升级https的操作

# 前置条件

  • 已有服务器
  • 已有证书

# 关键代码添加

将下载好的证书放置在项目目录下

let https = require("https");
let fs = require("fs");

const httpsOption = {
    key: fs.readFileSync("./[证书目录]/xxx.key"),
    cert: fs.readFileSync("./[证书目录]/xxx.pem")
}

https.createServer(httpsOption, app).listen(18889);

# 重启/运行项目

示例地址:https://tiaocaoer.com:18889/rr?page=1

收藏 打印