'Error: listen EACCES: permission denied 0.0.0.0:3001

I have gone through many answers here, none of them fixed my error. Here What I have tried so far.

Environment:

win 10 pro v2004 build 19041.29

node v12.14.1
  1. used netstat -a -b to see if this port is being used by any other process. No process is using this port, also tried switching the port to 3000 getting same error.

  2. I use docker-desktop and wsl2, so also disabled all virtual network adapter one by one. Tried after killing all other docker services.

  3. Restarted my pc.

  4. Tried running npm start through powershell as administrator

Server.js

const app = require('./src/app');

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Litening on port ${port}...`);
});

Error:

events.js:200
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES: permission denied 0.0.0.0:3001
    at Server.setupListenHandle [as _listen2] (net.js:1289:21)
    at listenInCluster (net.js:1354:12)
    at Server.listen (net.js:1442:7)
    at Function.listen (C:\Users\sujeet\project\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (C:\Users\sujee\CustomerAPIs\server.js:4:5)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1333:8)
    at processTicksAndRejections (internal/process/task_queues.js:81:21) {
  code: 'EACCES',
  errno: 'EACCES',
  syscall: 'listen',
  address: '0.0.0.0',
  port: 3001
}


Solution 1:[1]

In Windows using the below steps:

Open PowerShell as Admin.

stop winnat with the command below:

net stop winnat

start winnat again with the command below:

net start winnat

Solution 2:[2]

It seems like Windows changed it default dynamic port range.

You can use this command to check your dynamic port range

netsh int ipv4 show dynamicport tcp

If the port you want to use is within the range, you can change it with this command

netsh int ipv4 set dynamic tcp start=10000 num=10000

You can change the start port number and the number of port you want.

Don't forget to reboot your computer after change.

Solution 3:[3]

It could be that the port is being used by some other program. Try running the termianl as an admin and try restarting the system. If the issue still persists find a way to kill the process running on the port.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 MikuZZ
Solution 3 Venkatesh A