关于 Node.js v12.16.2 中的 HTTPS 文档
在 Node.js 的官方文档中,HTTPS 是通过 https
模块实现的安全通信协议支持。此模块提供了创建安全 HTTP 服务器的功能,并基于 TLS/SSL 协议来加密数据传输。
以下是使用 Node.js 创建一个简单 HTTPS 服务器的代码示例:
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('path/to/private-key.pem'), // 替换为私钥文件路径
cert: fs.readFileSync('path/to/certificate.pem') // 替换为证书文件路径
};
https.createServer(options, (req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain' });
res.end('Hello Secure World!\n');
}).listen(443);
console.log