# 在 node 中如何开启 https
Issue
欢迎在 Issue 中交流与讨论: Issue 350 (opens new window)
Author
在 express
中开启 https,如下代码所示
import path from 'path'
import fs from 'fs'
import express from 'express'
import http from 'http'
import https from 'https'
const app = express();
const cred = {
key: fs.readFileSync(path.resolve(__dirname, '../key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, '../cert.pem'))
}
const httpServer = http.createServer(app)
const httpsServer = https.createServer(cred, app)
httpServer.listen(8000);
httpsServer.listen(8888);