Certificate/key stop working on restart of node.js on Windows PC

I have a node.js webserver running on my Windows PC, and the certificate and key that certbot generated seem to work fine, however when I restart my PC, VS Code outputs this error in the console:

Error: EPERM: operation not permitted, open 'C:/Certbot/live/hdev22.nl/fullchain.pem'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at Object.<anonymous> (C:\Users\Hidde\Documents\Programming\Website\server.js:133:14)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -4048,
  syscall: 'open',
  code: 'EPERM',
  path: 'C:/Certbot/live/hdev22.nl/fullchain.pem'
}

I'm using Certbot 1.22.0, and I don't know how to solve this issue. To me it seems it requires permission to open the files, however I find that weird since it just works again once I renew the certificate using certbot, and I don't want to keep on renewing everytime I restart my PC. Does anyone know how to resolve this issue?

1 Like

When you created the certificate which user account were you running as, and which user account is your webserver process running as? It just looks like permissions.

4 Likes

I am always using the same user account (there's only one user account on my PC)

Which version of Windows are you using and which Anti Virus products do you have installed? Could "Controlled folder access" be enabled?

4 Likes

I am using Windows 11 Home Version 21H2, I don't have any anti virus products installed. A few days ago I also reset my PC (not from an external drive or anything though), trying to fix this issue, so there aren't that many programs on my PC (I did choose the option to keep my personal files, I don't know if any of that could be causing the issue...) Controlled folder access is turned off.

1 Like

"Houston... we have found the problem." - LOL

3 Likes

Just for fun can you try https://certifytheweb.com - you just add a new managed certificate and also add a Task to convert the final certificate into the format you need (Deploy to Generic Server, or just Deploy to Apache should work as all you really need are the files.).

While it's not a fix for certbot, the app (which I develop) is built specifically for Windows and is actually developed on Windows 11 (pro). Technically there should be no real difference between using one app or another to produce these files but it does seem like there is an odd permission issue happening. I suspect it may be more to do with node than certbot but trying a different app to produce the files may help identify which side the problem is on.

4 Likes

No no, the problem was already earlier in OPs post:

:sweat: :grin: :rofl:

3 Likes

Thanks, I'll look into it.

3 Likes

So I've given Certify the Web a try, but I couldn't figure it out yet (I'm pretty much a beginner in web development, for those that hadn't noticed yet by the software I use) but eventually I just ended up copying the files from Certbot/archive to a different folder, and that seems to have done it, now when I restart, it doesn't give the error anymore that I was getting before. I'm guessing it just has something to do with Windows messing something up in that folder(?), I don't know. But hey, it works!

3 Likes

You mean Windows?

Install Docker and run your websites in there, it's easier. Also install WSL and learn your way around unix systems. (You probably need Windows 10/11 pro for docker)

2 Likes

Yeah, I mean Windows and NodeJS. I'll take a look at Docker.

1 Like

NodeJS is probably fine. It's getting the "newcomer hate" despite being several years old.

It's about the right tool for the right job.

Also, VPSs are cheap: good ones (hetzner, scaleway, digitalocean, aws lightsail, azure, google cloud) start at 4.5 eur/month (billed per hour, even).

And you get a free one on google cloud (a tiny one, but it's good).

2 Likes

Well if we're talking tech, Visual Studio on windows has excellent productivity - a new .net core app (such as an API or website) will automatically get a dev certificate and you can even run the same app via windows, linux (WSL) or in docker. You can build an API and make it self documenting using Open API then auto generate a JS client (assuming your making a web app that talks to an API). Really most API development is eventually heading towards cloud functions (written in whatever language, usually backed by a cloud db) rather than running you own server etc.

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.