Uncaught exception listen EACCES: permission denied 127.0.0.1:8848
Today morning I turned on my laptop and tried to run a Node JS application. Then I suddenly got the following error in the console.
Uncaught exception listen EACCES: permission denied 127.0.0.1:8848
I tried to open currports and check what process is using that port exactly. Surprisingly the port 8848 isn’t used by any process. It’s free, but Windows won’t allow me to use that port for some reason!
I searched all over the internet and found the following command! Finally, that’s what happens to port 8848! It seems the port 8848 is excluded, even though it is not in used by anything. (WTF?)
netsh interface ipv4 show excludedportrange protocol=tcp
Then I found that Docker for Windows and Hyper-V are responsible for all of those excluded port ranges above. But wait, I’m using docker for years and I have never faced this problem until today. The reason for that is those port ranges are dynamic and will change every time I restart the Windows.
So just a simple restart should solve the problem, right? Not exactly! For some people, it seems like all those port ranges are increasing by 1 for each reboot. Then you might need hundreds of restarts to fix the issue. Obviously not a good solution!
Here is the correct way to fix the issue! Open Command Prompt or Power Shell as administrator.
Disable Hyper-V and then restart Windows.
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
After restarting, reserve the port you want so Hyper-V doesn’t reserve it back.
netsh int ipv4 add excludedportrange protocol=tcp startport=8800 numberofports=100
Re-Enable Hyper-V and restart Windows
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All