44

Has anyone experienced something liked this with node:

I was running Angular, my Windows crashed and restarted and now when I try ng serve I'm getting:

Error: listen EACCES: permission denied 127.0.0.1:4200
    at Server.setupListenHandle [as _listen2] (net.js:1253:19)
    at listenInCluster (net.js:1318:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1451:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:61:10)

I also tried ng serve --port 4201

Same result.

NOTE: Before Windows restarted I was running the app in WSL. After, I tried WSL and Powershell.

Update: It is even happening with a new project.

3
  • Try to uninstall and reinstall the whole WSL distro and redo all the steps. Or redo the steps in a newer distro install. Does this also occurs?
    – Biswapriyo
    Commented May 16, 2019 at 20:21
  • I'll try that. Right now, I already reinstalled node on Windows and check if the port was being used, it is not. Thanks for the advice, let you know if it worked. Commented May 16, 2019 at 20:26
  • I uninstall Ubuntu and installed Debian and the problem continues Commented May 16, 2019 at 20:49

10 Answers 10

39

In my case the error appears because the port used belong to reserved ports for Hyper-V.

This port range changes when I restart my computer, so sometimes I get the error sometimes no.

To check reserved ports by windows you can use(cmd/powershell):

netsh interface ipv4 show excludedportrange protocol=tcp

The issue is described in: https://github.com/microsoft/WSL/issues/5514

General workround (in comment 554587817): https://github.com/docker/for-win/issues/3171#issuecomment-554587817

Fast workround: choose a port that not belong to reserved ranges

1
  • Aha! This might be the problem for me too. 3000 is in that range. I wish there was a better error than access denied, since we tend to associate that with 'port in use', not 'port reserved'. Commented May 19, 2021 at 20:34
26

One Windows restart isn't enough, I restarted twice and the problem is gone.

Sorry, I don't have anything more technical.

Except: 1: Try not to develop on WSL from a Windows folder.

10
  • 2
    You saved my day by restarting windows twice. Commented Oct 13, 2019 at 12:36
  • 2
    I'm glad to have helped you. It is not a pretty answer, but it is not a pretty problem neither. Commented Oct 13, 2019 at 13:13
  • This has also helped me with my EACCES that wasn't related to node (and I don't even think it was WSL related, but I use WSL). When in doubt try turning it off and on again twice.
    – Barnaba
    Commented May 26, 2020 at 13:41
  • it fixed my issue (happened after i did windows updates)
    – CMS
    Commented Jun 25, 2020 at 15:39
  • 1
    Don't know how but it worked. Commented Apr 2, 2021 at 11:55
15

kudos to @fambrosi to find the thread and https://github.com/docker/for-win/issues/3171#issuecomment-788808021. Here is the command to solve this annoying issue.

net stop winnat
netsh int ipv4 set dynamic tcp start=49152 num=16384
netsh int ipv6 set dynamic tcp start=49152 num=16384
net start winnat
3
4

For me it was that node is listening on the wrong network interface.

After using docker it was using the docker network interface as primary.

Disabling the network interface to force node to use the correct interface did the trick.

3

I also Faced the same issue while trying ng serve command on the terminal.

an unhandled exception occurred: listen EACCES: permission denied 127.0.0.1:4200
see "C:\Users\MyUser\AppData\Local\Temp\ng-At4Tad\angular-errors.log" for further details.

Solution: Simply modify the command as

ng serve --port 4401
1
  • C:\Users\MyUser\Desktop\AngularExample>ng serve --port 4401 10% building 3/3 modules 0 activei 「wds」: Project is running at localhost:4401/webpack-dev-server i 「wds」: webpack output is served from / i 「wds」: 404s will fallback to //index.html ** Angular Live Development Server is listening on localhost:4401, open your browser on localhost:4401 ** i 「wdm」: Compiled successfully. Commented Feb 6, 2020 at 12:46
3

Restart was not enough! The only way to solve the problem is by the following:

You have to kill the service which run at that port.

At cmd, run as admin, then type :

netstat -aon | find /i "listening"

Then you will get a list with the active service, search for the port that is running at 4200 and use the process id which is the last column to kill it by:

taskkill /F /PID 2652
2

Adding to the growing list of things that might be the issue: I was using ExpressVPN on my computer, this somehow interfered with binding any localhost port. Uninstalling + restarting fixed the issue for me!

1
  • Indeed. To fix the issue: disconnect VPN Express & reconnect again.
    – roland
    Commented Nov 17, 2020 at 21:01
1

Same issue for me, triggered by running Vue dev server on port 3000. In my case, I wanted to browse to localhost:3000 via a custom host-mapped local domain name (e.g. mysite.dev) instead, so I incorrectly set my local Apache configuration to listen on 0.0.0.0:3000 and defined <VirtualHost *:3000>. So Apache was already using the port.

0

I recently updated my docker to the latest version and my angular application started giving me this error. After investigating I found that port 4200 (the default port which angular applications use) is occupied by other applications.

I ran the application with a different port and solved the problem.

ng serve --port 4000
0

If the above answers don't fix your issue, your port could be bound via netsh. You can use the following command to see if your port proxies information to elsewhere; I had bound port 3000 to another ip and received this error as a result.

netsh interface portproxy show all 

If you do have the port bound, you can remove the port binding with:

netsh interface portproxy listenport=(your port) listenaddress=(ip address)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .