node running server throw Error regarding already runinng port - node.js

Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8082
}
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8082

First findout your processID for your running process
lsof -i:1234(your port ID)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Google 55523 ssurisettii 42u IPv6 0x53ab9cb514809733 0t0 TCP localhost:53991->localhost:us-cli (CLOSE_WAIT)
Google 55523 ssurisettii 45u IPv6 0x53ab9cb51480d473 0t0 TCP localhost:53989->localhost:us-cli (CLOSE_WAIT)
Google 55523 ssurisettii 46u IPv6 0x53ab9cb514809d53 0t0 TCP localhost:53990->localhost:us-cli (CLOSE_WAIT)
this ways shows,
Now you kill the your related processID
suppose your port id contains processID 1234
then **** kill -9 1234 ***

Related

https not working in Linux with node/express/webpack

I have a nodejs application, I am able to configure https and run it locally on my windows machin, but when I do the same run on my Linux machin it fails with below error.
EADDRINUSE: address already in use 0.0.0.0:3006
events.js:282
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use 0.0.0.0:3006
at Server.setupListenHandle [as _listen2] (net.js:1308:16)
at listenInCluster (net.js:1356:12)
at doListen (net.js:1495:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1335:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '0.0.0.0',
port: 3006
}
As suggested by other I tried 'netstat -plnt' but the port 3006 is nowhere used, so nothing to kill.
Not sure if this is code issue or OS issue.
[Update] chnaged the port to 3006
netstat -plnt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
Try using fuser 1223/tcp to get the process and
fuser -k 1223/tcp to kill the process running on the specific port

Getting Error of Unhandled 'error' event events.js Angular 6

I am new to angular and trying to setup an existing project on the server. I have setup the project on the root of the server and moved my build to apache folder (/var/www/html). I have a carousel on the home page and getting errors of main.da2430b946ec091e1c9e.js:1 ERROR TypeError: Cannot read property 'toArray' of undefined. I am using bootstrap carousel on home page.
When i run the command node project.js which have the NPM PACKAGES API ROUTES ADMIN ROUTES defined, i am getting error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8081
at Server.setupListenHandle [as _listen2] (net.js:1360:14)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
at Object.<anonymous> (/home/sam/server/routes/chat.js:36:8)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/sam/server/routes/api.js:26:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
I read somewhere that this error might be because of the port being used by other service. So i run below comands:
sudo lsof -i :80 # checks port 81
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 886 sam 4u IPv6 18050 0t0 TCP *:http (LISTEN)
apache2 2559 www-data 4u IPv6 18050 0t0 TCP *:http (LISTEN)
apache2 2588 www-data 4u IPv6 18050 0t0 TCP *:http (LISTEN)
sudo lsof -i :80 # checks port 80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 886 sam 4u IPv6 18050 0t0 TCP *:http (LISTEN)
apache2 2559 www-data 4u IPv6 18050 0t0 TCP *:http (LISTEN)
apache2 2588 www-data 4u IPv6 18050 0t0 TCP *:http (LISTEN)
sudo lsof -i :8081 # checks port 80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 8468 sam 10u IPv6 54277 0t0 TCP *:tproxy (LISTEN)
sudo lsof -i :8081 # checks port 8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 8468 sam 10u IPv6 54277 0t0 TCP *:tproxy (LISTEN)
Here is the Angular version details:
Angular CLI: 6.0.8
Node: 8.14.0
OS: linux x64
Angular: 6.0.9
Can anyone help me with this issue. I have spend many hours on it and didn't found any working solution.
Thanks in Advance.

Amazon EC2 Error: listen EACCES 0.0.0.0:80

I have already added the HTTP TCP Port 80 to the inbound rules, but I still get the error:
Error: listen EACCES 0.0.0.0:80
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1338:19)
at listenInCluster (net.js:1396:12)
at doListen (net.js:1505:7)
at _combinedTickCallback (internal/process/next_tick.js:141:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
You probably have to run your node.js script with sudo as you want to listen on port 80.
You cannot run a process that listens on low ports (below 1024) without root privileges.
You either try to run as sudo, as stated above, or start to use a reverse proxy (nginx for instance), start the process on another port and use the reverse proxy to forward the calls from port 80 to whatever port you started the process on.
The error code EACCES means you don't have proper permissions to run applications on that port. On Linux systems, any port below 1024 requires root access.
you need to use reverse proxy to forward the calls from port 80 to 8080 for example.

I'm getting an unhandled error when trying to run node server

So, I'm really new to node and I feel like this might be something very simple but I can't figure it out. I installed the dependencies but when I try to start the server by doing "node server" I get this error:
Vladimirs-MBP:comeat-server Vladimir$ node server
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL 18.194.133.202:3001
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1350:19)
at listenInCluster (net.js:1408:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1517:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
Your 3001 port is already used by some service, please change the port
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end();
}).listen(8080); //the server object listens on port 8080
You can use these commands to check what ports are being used:
1. sudo lsof -i -P -n | grep LISTEN
2. netstat -tulpn | grep LISTEN
You can kill that process number using
sudo kill -9 process_number
Your 3001 port is in use. you should use another port or kill 3001 port and then use it.
for example
sudo kill -9 $(sudo lsof -t -i:3001)

nodejs error EADDRINUSE

I get this when i type "node site.js" im 100% sure im not running this node twice.
Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1262:14)
at listen (net.js:1298:10)
at Server.listen (net.js:1376:9)
at Server.listen.Server.attach (/root/node_modules/socket.io/lib/index.js:228:9)
at Timeout._onTimeout (/root/nodejs/site.js:1005:29)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3000 }
Im using FEDORA 23
Your site.js tries to listen twice on that port or something (another process) is already listening on port 3000. Find the service and stop/kill it. This command should help: lsof -i | grep 3000
Try running killall node, then node site.js again. If that doesn't work, at least you can rule out Node from the cause of this.
Your site is listening twice to that port. You can check in your code whether you have 2 instructions .listen()

Resources