Listening to Port 1880 fails on Windows - node.js

I am not able to start a server listening to port 1880. I tried this simple code in Node.js:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(1880);
Which gives me the following error:
Error: listen EACCES: permission denied 0.0.0.0:1880
[90m at Server.setupListenHandle [as _listen2] (net.js:1283:19)[39m
[90m at listenInCluster (net.js:1348:12)[39m
[90m at Server.listen (net.js:1436:7)[39m
at Object.<anonymous> (C:\Users\mmueller\Desktop\test\test.js:6:4)
[90m at Module._compile (internal/modules/cjs/loader.js:956:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:812:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:724:14)[39m
[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)[39m
[90m at internal/main/run_main_module.js:17:11[39m
Emitted 'error' event on Server instance at:
[90m at emitErrorNT (net.js:1327:8)[39m
[90m at processTicksAndRejections (internal/process/task_queues.js:80:21)[39m {
code: [32m'EACCES'[39m,
errno: [32m'EACCES'[39m,
syscall: [32m'listen'[39m,
address: [32m'0.0.0.0'[39m,
port: [33m1880[39m
}
What I tried:
Checked if there is another program listening on this port (which is
not the case)
Executed command in admin console
Disabled windows firewall
Disabled Kaspersky tools
Still no success.
With port 1881 it also doesn't work. So some port-range has no access.
But with e.g. port 18800 it works.
What else can I do to figure out why I don't have access to listen to port 1880? What else could be blocking this port access if not firewall or anti virus software?

I have found the issue: Hyper-V was reserving some ports on windows.
netsh int ip show excludedportrange protocol=tcp

Related

permision denied on port 3000 on nodejs

when i run my nodejs project on port 3000, get following error:
Error: listen EACCES: permission denied :::3000
at Server.setupListenHandle [as _listen2] (node:net:1330:16)
at listenInCluster (node:net:1378:12)
at Server.listen (node:net:1465:7)
at Function.listen (F:\Projects\NodeJS\Nodejs start\Nodejs start\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (F:\Projects\NodeJS\Nodejs start\Nodejs start\app.js:34:5)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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:77:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1357:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -4092,
syscall: 'listen',
address: '::',
port: 3000
Not only on port 3000, but also on any port, the program does not run, and the mentioned error occur.
for solving this problem, i run net stop winnat on CMD, i get:
The Windows NAT Driver service is not started.
for start the winnat, i run net start winnat , i get
The Windows NAT Driver service was start successfully.
But the problem was not solved.Is there any other way but to restart the system?
When reading an environment variable, you should convert it to a number.
Try adding parseInt() to the variable:
const port = parseInt(process.env.PORT) || 3000;
You can try On Windows systems, restarting the service "Host Network
Service" may resolve the issue.
or try to restart your computer more than one time
or try open CMD under admin rights and run :
net stop winnat
net start winnat

My node process doesn't end on my EC2 server

SO I made an EC-2 Server and I've installed node.js on it. Then, I connected it to port :3000. It was fine untill I noticed that the port was never closed. I had no idea it was still open and tried 'npm run start' multiple times. I just found out that it was alive so I got the PID through "lsof -i TCP:3000" and killed it using 'Kill -9 "PID#" and tried to run the port again. However, it gave me :
node:events:342
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1306:16)
at listenInCluster (node:net:1354:12)
at Server.listen (node:net:1441:7)
at Function.listen (/home/ec2-user/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/ec2-user/index.js:12:5)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1333:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3000
}
So I searched if the port was open again, and it was still open with a different PID. I tried killing it over and over, but it kept showing up with a differnt PID.
If there is something worng or unclear with my question please tell me, I jsut started fiddling with EC2 and all this server things, so I don't know which informations are further required to solve this.
I solved it!!! I typed
killall5 -9
and killed everything and it stopped!

Cloud 9 Node js. Can't connect to process.env.Port anymore. EADDRINUSE Error

Have tried do work out this simple code in cloud9
but it seems like some process is already located
on process.env.PORT and I can't seem to find it.
Have tried killing nodes searching for nodes.
And i'm not entirely sure how to connect to port like 3000 on cloud9. (localhost:3000)
Debugger listening on port 15454
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1234:14)
at listen (net.js:1270:10)
at Server.listen (net.js:1366:5)
at Object.<anonymous> (/home/ubuntu/workspace/script.js:5:4)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
The code
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(process.env.PORT);

running basic http server using node.js on Mac

I'm new to node.js and was trying to run the following training example for setting up a basic http server on my mac (OS X Yosemite 10.10.3):
var http = require("http");
http.createServer(function (request, response) {
request.on("end", function () {
response.writeHead(200, {
'Content-Type': 'text/plain'
});
response.end('Hello HTTP!');
});
}).listen(8080);
I get the following error when executing the code:
$ node http.js events.js:85
throw er; // Unhandled 'error' event
^ Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1156:14)
at listen (net.js:1182:10)
at Server.listen (net.js:1267:5)
at Object. (/Users/sumankalyan/WebstormProjects/Node-Server/http.js:25:4)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Not sure if this is a localhost config issue or something else. Any help much appreciated.
Another application is using the port 8080. You can run
lsof -i :8080
to see what it is. You can also just try another port.

EADDRINUSE with Node.js on OpenShift

Writing a test application in Node.js running on OpenShift and it currently will not start.
This is my code:
#!/bin/env node
var http = require('http');
var ip = process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_NODEJS_PORT;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(ip, port);
console.log('Server running');
I get the error
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:884:11)
at Server._listen2 (net.js:1003:19)
at listen (net.js:1044:10)
at Server.listen (net.js:1104:5)
at Object.<anonymous> (/var/lib/openshift/52854c6f4382ec071400051d/app-root/runtime/repo/server.js:11:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
DEBUG: Program node server.js exited with code 8
Which seems to mean I can't bind to the port. I've found various information on why this might be but none of it seems relevant - it all seems related to permissions but surely the point of process.env.OPENSHIFT_NODEJS_* is I have permission to bind to it?
It means some other process is using your port process.env.OPENSHIFT_NODEJS_PORT. EACCESS would mean permission denied, not EADDRINUSE. Try changing to unused ports like 8080. You can check used ports with :
netstat -tulpn
netstat -tulpn | grep :$OPENSHIFT_NODEJS_PORT //filter by your port

Resources