How to fix Listen EADDRINUSE in ubuntu - node.js

How can I resolve this issue?
1|server | at listenInCluster (net.js:1327:12)
1|server | at Server.listen (net.js:1414:7)
1|server | at Object.<anonymous> (/root/signalmaster/server.js:41:8)
1|server | at Module._compile (internal/modules/cjs/loader.js:776:30)
1|server | at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
1|server | at Module.load (internal/modules/cjs/loader.js:653:32)
1|server | at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
1|server | at Function.Module._load (internal/modules/cjs/loader.js:585:3)
1|server | at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
1|server | code: 'EADDRINUSE',
1|server | errno: 'EADDRINUSE',
1|server | syscall: 'listen',
1|server | address: '::',
1|server | port: 8080 }
My server and turnserver status is Online but our clients can't communicate or see each other.
UPDATE:
see this pm2 list

try in the console :
killall node
and the problem should be fixed

The following IP address already used. In same IP address you can run the server by different ports. The port must be opened.
* If it's live server and already running httpd .
<VirtualHost *:80>
ServerName api.xxxx.com
#DocumentRoot /var/www/test
CustomLog /var/www/test/access.log common
ErrorLog /var/www/test/error.log
UseCanonicalName Off
UserDir disabled
<Location "/">
ProxyPreserveHost On
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
</VirtualHost>

Related

Command not working in the middle of a Heroku tutorial [duplicate]

This question already has answers here:
Port in use when launching Node.js app with Heroku Foreman
(2 answers)
Error: That Port is already in use (Heroku/Django)
(1 answer)
Closed 21 days ago.
I am following a tutorial in Heroku documentation (https://devcenter.heroku.com/articles/getting-started-with-nodejs) and hit the problem hereafter, when running the command:
% heroku local web
On a Mac (M1), though all the first part of the tutorial went fine, in the section Run the app locally, this is what I get (not what is supposed to happen):
myveryname#Me-MacBook-Air node-js-getting-started % heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
2:20:52 PM web.1 | > node-js-getting-started#0.3.0 start
2:20:52 PM web.1 | > node index.js
2:20:52 PM web.1 | node:events:491
2:20:52 PM web.1 | throw er; // Unhandled 'error' event
2:20:52 PM web.1 | ^
2:20:52 PM web.1 | Error: listen EADDRINUSE: address already in use :::5000
2:20:52 PM web.1 | at Server.setupListenHandle [as _listen2] (node:net:1432:16)
2:20:52 PM web.1 | at listenInCluster (node:net:1480:12)
2:20:52 PM web.1 | at Server.listen (node:net:1568:7)
2:20:52 PM web.1 | at Function.listen (/Users/myveryname/Documents/Heroku/node-js-getting-started/node_modules/express/lib/application.js:635:24)
2:20:52 PM web.1 | at Object.<anonymous> (/Users/myveryname/Documents/Heroku/node-js-getting-started/index.js:10:4)
2:20:52 PM web.1 | at Module._compile (node:internal/modules/cjs/loader:1126:14)
2:20:52 PM web.1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
2:20:52 PM web.1 | at Module.load (node:internal/modules/cjs/loader:1004:32)
2:20:52 PM web.1 | at Function.Module._load (node:internal/modules/cjs/loader:839:12)
2:20:52 PM web.1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2:20:52 PM web.1 | Emitted 'error' event on Server instance at:
2:20:52 PM web.1 | at emitErrorNT (node:net:1459:8)
2:20:52 PM web.1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
2:20:52 PM web.1 | code: 'EADDRINUSE',
2:20:52 PM web.1 | errno: -48,
2:20:52 PM web.1 | syscall: 'listen',
2:20:52 PM web.1 | address: '::',
2:20:52 PM web.1 | port: 5000
2:20:52 PM web.1 | }
[DONE] Killing all processes with signal SIGINT
2:20:52 PM web.1 Exited with exit code null
myveryname#Me-MacBook-Air node-js-getting-started %
Searching the net seems to suggest that Mac may make use of the 5000 port on its own.
When I look at http://localhost:5000/ in my web browser, it looks like the port 5000 is indeed somewhat busy (though the page shows completely white).
But I have no idea what it is doing. And even if I restart the computer that does not change.
I must not be the only one to have hit this issue. So what is the correct way to handle this situation and be able to continue with the end of the tutorial?
On mac Air Play Control Center listens on port 5000.
You can disable airplay receiver to release the port or you can change the port on your code to something like 5001
you can also run this command lsof -i :5000 to check which process is using 5000 port
Reference:https://developer.apple.com/forums/thread/682332

Getting an error while running "nodemon app" comannd

i've downloaded express package and nodemon, I created a server and rendered all of my ejs files . while running "nodemon app" command I'm getting this error, what specifically the problem is? :
PS C:\Users\user\Desktop\my port> nodemon app
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
events.js:291
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1316:16)
at listenInCluster (net.js:1364:12)
at Server.listen (net.js:1450:7)
at Function.listen (C:\Users\user\Desktop\my port\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (C:\Users\user\Desktop\my port\app.js:16:5)
at Module._compile (internal/modules/cjs/loader.js:1251:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1343:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...
Your system has something already running on port 3000.
you can do either of 2,
Kill process running on 3000
Or Use different port in your current app (like 3001, 5000, etc)
hi use this and kill the process directly;
netstat -ano | findstr :XXXX
XXXX <<<<----put the number of the port you have problem, system show it always, then when you press enter the system show you a message with a real port that one is what you need killing, so put this:
taskkill /F /PID XXXX
XXXX <<<<----the number of the port you want to kill and what system gave you after the first command
type this in command prompt
netstat -ano | findstr :XXXX <-THIS IS THE PORT NUMBER YOU used
And it will give you something like this
TCP 0.0.0.0:8080 || 0.0.0.0:0 || LISTENING | tttt
TCP [::]:8080 || [::]:0 || LISTENING || tttt<--thiss is the number you needed
then type this in command prompt
taskkill /PID tttt /F <--then enter
result will be something like -->
The process with PID tttt has been terminated.

Error: listen EADDRNOTAVAIL: address not available **.***.***.**:3004

I have installed node.js on a google cloud server. But I'm getting an error while running the command sudo node test.js. The web root is /var/www/*******/ and the virtual host file is /etc/apache2/*****.conf
I'm trying to access it through the port 3004. I have enabled it in the firewall as well.
Virtual host configuration:
<VirtualHost *:80>
ServerName domainname.com
ServerAdmin test#gmail.com
DocumentRoot "/var/www/******/"
<Directory "/var/www/******/">
Options -Indexes
AllowOverride All
Require all granted
</Directory>
</Virtualhost>
<VirtualHost *:3004>
ServerName domainname.com
ServerAdmin test#gmail.com
DocumentRoot "/var/www/******/"
<Directory "/var/www/******/">
Options -Indexes
AllowOverride All
Require all granted
</Directory>
</Virtualhost>
===============================================================
Error:
Server running at http://domainname.com:3004/
events.js:173
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL: address not available **.***.***.**:3004
at Server.setupListenHandle [as _listen2] (net.js:1239:19)
at listenInCluster (net.js:1304:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1443:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:63:10)
Emitted 'error' event at:
at emitErrorNT (net.js:1283:8)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
Please help.
Thanks,
Vishnu.

How can I start a NodeJS in the background?

I tried to start a project
node index.js , I got this
events.js:173
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1255:14)
at listenInCluster (net.js:1303:12)
at Server.listen (net.js:1391:7)
at Function.listen (/home/forge/bheng/public/ios-base-api/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/forge/bheng/public/ios-base-api/index.js:156:5)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1282:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:777:11)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Then, I ran lsof -i | grep 3000, I got
node 6159 root 19u IPv6 58371978 0t0 TCP *:3000 (LISTEN)
Then, I ran ps -aux | grep node, I got
root 448 0.0 1.4 569912 29600 ? Ssl 21:21 0:00 node /usr/bin/pm2 update
root 1266 0.0 1.5 569400 31628 ? Ssl 21:28 0:00 node /usr/bin/pm2 update
root 6159 1.0 2.4 845540 49568 ? Ssl 21:46 0:02 node /home/forge/bheng/public/ios-base-api/index.js
root 6482 0.0 0.0 11244 948 pts/3 S+ 21:50 0:00 grep --color=auto node
root 32233 0.0 1.4 569912 29876 ? Ssl 21:14 0:00 node /usr/bin/pm2 update
I just want to start my nodejs app in the background and be able to access my endpoint anytime.
Why is this so complicated ? 😭
There are many packages which can help you. Check out pm2, forever
Both of them allow you to run your project in background and auto-reload is possible too :)

Socket.io on elastic beanstalk error

I get an error
http://lowcost-env.b8cgexs3tc.us-west-2.elasticbeanstalk.com/socket.io/?EIO=3&transport=polling&t=LliRJNu 404 (Not Found)
when I have deployed my app and try to run it. Socket.io works great locally on localhost.
My server-setup:
var server = require('http').Server(express);
var io = require('socket.io')(server);
server.listen(8080);
Client:
io.connect('LowCost-env.b8cgexs3tc.us-west-2.elasticbeanstalk.com')
The errorlog from Amazon show:
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at Server.listen (net.js:1391:5)
at EventEmitter.listen (/var/app/current/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/var/app/current/server/index.js:8:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
Tue, 09 May 2017 11:30:38 GMT express-session deprecated undefined resave
option; provide resave option at server/app.js:27:9
Tue, 09 May 2017 11:30:38 GMT express-session deprecated undefined
saveUninitialized option; provide saveUninitialized option at server/app.js:27:9
In Amazon I have disabled proxy so I'm not using nginx. Whats the problem here?

Resources