How do I access other IPv6 Adresses from my vps - node.js

Hello StackOverflow!
I recently bought a VPS, where I was given 64 IPv6 addresses, however I find myself unable to use any of them except :1. The IPv6 gateway looks like this (masked with x for security reasons) xxxx:xxxx:x:xxx::a where a is 1 to 64, I should have all of them available to my service, I'm just not able to use any of them except 1. It says that 1 is automatically assigned to the OS installed on my VPS, does that mean I have to assign the rest of the addresses as well? If so, how do I do that?
Here's the code I used in Node.js to try this.
const Express = require("express");
const App = Express();
App.use(Express.static(__dirname+"/www"));
const Listener = App.listen(1024, "xxxx:xxxx:x:x:xx::2", () => {
const addr = Listener.address();
console.log("Listening on " + addr.address + ":" + addr.port);
});
The error that I get when I'm starting it is:
Error: listen EADDRNOTAVAIL xxxxx:xxxx:x:x:xx::2:1024
at Server.setupListenHandle [as _listen2] (net.js:1318:19)
at listenInCluster (net.js:1383:12)
at doListen (net.js:1509:7)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1362:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)

Hello!
I managed to resolve this on my own after finding the right keywords to google for with the help of #Paul
The solution was to add each address to the interfaces file.
I used the command:
sudo ifconfig eth0 inet6 add xxxx:xxxx:x:x:xx::a/64

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!

NodeJS - Error: listen EADDRNOTAVAIL: address not available

I am running a Node app that should be hosted on a local server.
At the moment, I am sending just a plaintext response.
const http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {ContentType: 'text/plain'});
res.end("test");
});
When I listen to the localhost everything works fine and I am able to send the request from my browser.
server.listen(3000, '127.0.0.1'); // works fine, on the same machine
However, if I try to listen to a port on my LAN network by typing the router's IP, I get an error.
server.listen(3000, '192.168.0.1'); // causes an error
Error: listen EADDRNOTAVAIL: address not available 192.168.0.1:3
000
at Server.setupListenHandle [as _listen2] (net.js:1253:19)
at listenInCluster (net.js:1318:12)
at doListen (net.js:1451:7)
at process._tickCallback (internal/process/next_tick.js:63:1
9)
at Function.Module.runMain (internal/modules/cjs/loader.js:7
57:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1297:8)
at process._tickCallback (internal/process/next_tick.js:63:1
9)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
I have tried this with my public IP address unsuccessfully.
Is there any way to listen to a port on a LAN server so that I can send requests from any computer on the network?
Also, I would later like my application to run on any computer on any LAN network. How can I dynamically add my host?
Try this
server.listen(3000, '0.0.0.0');
you can access your node application from other machine
e.g
your lan ip is 192.168.0.101 then you can browse 192.168.0.101:3000 from other machine
I got this error, the issue was I had a VPN connected
Be careful with your IP.
Sometimes it changes. When I work with Node I have to check the ipconfig in Shell... I hope with that it could help if someone else have the same problem...
The right IP address actually turned out to be 192.168.0.104.
The IP address of a server machine should be used, not that of a router.

How to use app.listen(port, host) with public hostname?

Can I put public domain name as host argument in app.listen(port, host)?
I know my ip, and I have 3 domain names on this ip. domain1.com, domain2.com all on same ip. Now, I'm using switch in app.get('/') to routing request of different domain names. However, I'm wondering is there a way to route host when setting up app.listen.
I found the entry of app.listen([port[, host[, backlog]]][, callback]) is really vague on expressjs website. There's nothing about the "host" argument. I know it can be set to localhost or 127.0.0.1. But my code failed when I put public domain name in it.
Can anybody explain how the host argument works in app.listen? Thank you.
var express = require('express');
var app = express();
app.get('/', function(req, res) {res.send("hello")});
app.listen(3000, "my.domain");
Error code:
Error: listen EADDRNOTAVAIL: address not available myip:3000
at Server.setupListenHandle [as _listen2] (net.js:1281:19)
at listenInCluster (net.js:1346:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1485:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:65:10)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1325:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRNOTAVAIL',
errno: 'EADDRNOTAVAIL',
syscall: 'listen',
address: 'myip',
port: 3000
}
The server can't run.
Try to start server with hostname 0.0.0.0 and get access from other network points by your IP (check by ifconfig).
Find out the public ip of your public domain, then put it in the app.listen.
Example if your public ip is 1.2.3.4:
app.listen(3000,'1.2.3.4');

Error: listen EADDRINUSE: address already in use :::8080 while clicking on run script

Firstly I run this command (npm ndb server.js) then a debugging chrome window appear and after this
Actually, I got these error when I am trying to debug in my code and I clicked on run script after that a debugging chrome window appear then it give these wired error.
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (net.js:1279:14)
at listenInCluster (net.js:1327:12)
at Server.listen (net.js:1414:7)
at Function.listen (C:\Users\Abhishek kumar\natours\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (C:\Users\Abhishek kumar\natours\server.js:24:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1306:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
The error is quite explicit :
Error: listen EADDRINUSE: address already in use :::8080
means that some program is already listening on port 8080 (and you have an extra hint : the ::: says that it's listening on broadcast host using IPv6).
If you're curious what program is listening on that port, you could try to navigate to http://localhost:8080 and see what's displayed. If nothing is displayed then it's not one of your web apps. Maybe you have an HTTP proxy running on your machine (I have recently come across a malware that ran mitmproxy on target machines on port 8080 to intercept all traffic).
On Mac or Linux you can use lsof to get more information on the program listening on that port.
The command you want is :
$ sudo lsof -i :8080
Run this command.
killall node

Resources