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
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.
I use docker-desktop and wsl2, so also disabled all virtual network adapter one by one. Tried after killing all other docker services.
Restarted my pc.
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
}
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.
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.
In windows using the below steps:
Open PowerShell as Admin.
stop winnat with command below:
net stop winnat
start winnat again with command below: net start winnat
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.