尝试读取 fullchain.pem 时出现 EPERM 错误

EPERM error while trying to read fullchain.pem

我正在尝试在我的 Windows 10 计算机上使用 Node.js 托管一个 HTTPS 网站,但是 Node.js 突然无法读取 fullchain.pem 我使用 Let's Encrypt's Certbot.

获得

这是我的 Node.js 代码:

const fs = require("fs")
const https = require("https")
const FS_OPTIONS = {
    encoding: "utf-8",
    flag: "r",
}
const key = fs.readFileSync("C:/Certbot/live/subdomain.example.com/privkey.pem", FS_OPTIONS)
const cert = fs.readFileSync("C:/Certbot/live/subdomain.example.com/fullchain.pem", FS_OPTIONS)
https.createServer({ key, cert }, (req, res) => {
    // do stuff...
}).listen(8888)

但是,当我 运行 它时,我收到以下错误:

Error: EPERM: operation not permitted, open 'C:/Certbot/live/subdomain.example.com/fullchain.pem'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at Object.<anonymous> (D:\Users\...\index.js:8:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -4048,
  syscall: 'open',
  code: 'EPERM',
  path: 'C:/Certbot/live/subdomain.example.com/fullchain.pem'
}

我可以绕过它的唯一方法是 运行ning 作为管理员,但这很奇怪,因为以前不需要这样做。

如何将其恢复到以前的行为?

您只需要更改文件夹和子文件夹的访问权限:C:/Certbot

添加对用户的访问运行 nodejs。例如以下这个: https://v2cloud.com/tutorials/how-to-change-folder-permissions-on-windows-2016