gpt4 book ai didi

node.js - 错误 : ENOENT: no such file or directory, 打开 'C :\USER\family\Desktop\index\https-app\sever\ssl\ssl\server. crt

转载 作者:太空宇宙 更新时间:2023-11-04 02:10:26 24 4
gpt4 key购买 nike

我正在尝试使用 NodeJS 和 Express 设置 HTTPS 服务器,但出现以下错误: Screenshot of Error

这是我的代码:

'use strict'

const express = require('express')
const fs = require('fs')
const https =require('https')
const path = require('path')

const app = express()
const directoryToServe = 'client'
const port = 3443

app.use('./',express.static(path.join(__dirname,'..',directoryToServe)))

const httpsOptions = {
cert: fs.readFileSync(path.join(__dirname,'ssl','server.crt')),
key: fs.readFileSync(path.join(__dirname,'ssl','server.key'))
}

https.createServer(httpsOptions, app)
.listen(port, function()
{
console.log(`Serving the ${directoryToServe}/directory at https://localhost:${port}`)})

这是我的文件保存的地方: Screenshot of location of my files

最佳答案

删除sslfs.readFileSync(path.join(__dirname,'ssl','server.crt'))之间__dirnameserver.crt

fs将寻找另一个ssl不存在的目录 ...https-app\server\ssl\ssl\server.crt...https-app\server\ssl\ssl\server.key

'use strict'

const express = require('express')
const fs = require('fs')
const https =require('https')
const path = require('path')

const app = express()
const directoryToServe = 'client'
const port = 3443

app.use('./',express.static(path.join(__dirname,'..',directoryToServe)))

const httpsOptions = {
cert: fs.readFileSync(path.join(__dirname,'server.crt')),
key: fs.readFileSync(path.join(__dirname,'server.key'))
}

https.createServer(httpsOptions, app)
.listen(port, function()
{
console.log(`Serving the ${directoryToServe}/directory at https://localhost:${port}`)})

关于node.js - 错误 : ENOENT: no such file or directory, 打开 'C :\USER\family\Desktop\index\https-app\sever\ssl\ssl\server. crt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com