版权声明:可供读者学习参考使用 https://blog.csdn.net/weixin_40169642/article/details/83215171
看这篇文章的时候,希望你已经有自己的域名,并且申请了SSL证书。
如果还没有完成上述工作,请前往https://www.cnblogs.com/lxf1117/p/6650647.html
看下面的代码之前希望你了解nodejs的express 框架,如果还不了解,请前往https://blog.csdn.net/qq_empire/article/details/80933726
var https = require('https');
var privateKey = fs.readFileSync('./path/to/215083744800064.key', 'utf8');
var certificate = fs.readFileSync('./path/to/215083744800064.pem', 'utf8');
var options={key:privateKey, cert:certificate};
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3030');
app.set('port', port);
/**
* Create HTTPS server.
*/
var server = https.createServer(options,app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);