Socket.io on elastic beanstalk error - node.js

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?

Related

How to fix Listen EADDRINUSE in ubuntu

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>

Port specified when running node is undefined

The port is specified when i ran the node project says undefined.
> sf-chain#1.0.0 dev E:\System\dev\node\sf-chain
> nodemon ./app "HTTP_PORT=3002" "P2P_PORT=5002" "PEERS=ws://localhost:5001"
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./app HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001`
process.env.HTTP_PORT :: undefined
HTTP_PORT :: 3001
Listening for peer-to-peer connections on: 5001
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3001
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 (E:\System\dev\node\sf-chain\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\System\dev\node\sf-chain\app\index.js:28:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
[nodemon] app crashed - waiting for file changes before starting...
I ran the first instance using
npm run dev
const HTTP_PORT = process.env.HTTP_PORT || 3001;
The application starts successfully running on port 3001 since i didn't specify HTTP_PORT at the run command.
But when trying to run another instance by specifying HTTP_PORT using the below command
npm run dev HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001
I get this error.
Error: listen EADDRINUSE :::3001
Which means the HTTP_PORT specified at run time is seen as undefined that's why it's trying to using the 3001 port for the first instance.
Error: listen EADDRINUSE
- error comes when somthing is already running/listen on that port
Its because sometime instance of same nodejs acquire port and didnt kill/exit the process properly,
if you have Ubuntu check first which process is using port by
lsof -i :3001 // Port no.
then output will be some thing like this.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2496 nasiruddin 13u IPv6 37696 0t0 TCP *:3001 (LISTEN)
kill using PID
kill 2496
then start again

Server.listen() in node gives " Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing."

Apologies if some aspects of the question here are unclear as I am new to node & javascript. Please ask for further details
I have a node application that is connected to firebase using socketio. When the application is deployed on heroku, I get the following error:
Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
Nov 01 19:57:38 app/web.1: at Server.listen (net.js:1446:11)
Nov 01 19:57:38 app/web.1: at exports.default (/app/dist/server.js:8226:11)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:191:21)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:47:19)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at /app/dist/server.js:40:18
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:43:10)
Nov 01 19:57:38 app/web.1: at Module._compile (module.js:641:30)
Nov 01 19:57:38 app/web.1: at Object.Module._extensions..js (module.js:652:10)
Nov 01 19:57:38 app/web.1: /app/dist/server.js:212
Nov 01 19:57:38 app/web.1: throw error;
The description of the error is on this link :
https://nodejs.org/api/all.html#errors_err_server_already_listen
The listening code on my server.js is as shown:
const server = http.createServer(app).listen(port)
Any idea why this error is occurring? Should I close the server if the listen fails. If yes, how can I do it?
Thank you.
My bad. I got confused as the error was not occurring on my mac. The answer is in the error itself. The error was occurring as the listen method was being called twice. The second call was in some other module.

ERROR connecting to remote database server(NGINX) via tunneled localhost Node JS

error connecting: Error: Connection lost: The server closed the connection.
at Protocol.end (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:109:13)
at Socket.<anonymous> (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\Connection.js:109:28)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
--------------------
at Protocol._enqueue (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\Connection.js:130:18)
at Object.<anonymous> (C:\Users\Tony\Documents\TestServer\app.js:13:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
using this code
var express = require('express');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
port: '8888',
user: 'root',
password: 'xxx',
database: 'shop'
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
server is BITNAMI using google cloud
localhost is on windows, i can connect to the phpmyadmin through the browser but the script does not work. Thank you
Hi Bitnami developer here,
As you mentioned, you can access phpMyAdmin using the 8888 port because you opened a tunnel to access Apache and that application through that port. You would need to open a new tunnel to access MySQL directly because we configure the server to only listen to localhost for security reasons.
The source port of this new tunnel would be a different port (i.e 8989) and the destination would be localhost:3306 (3306 is the MySQL default port). You would need to modify your code to use the 8989 port instead of the 8888 one.
I hope this information helps.
Jota
To find out if the tunnel is really set up you can run.
sudo lsof -i -n | egrep '\<ssh\>'
you should get some lines out of that. If one of them is around these lines :
ssh 11704 root 3u IPv4 47283826 0t0 TCP [localip]:46286->[remoteip]:ssh (ESTABLISHED)
then the connection is on. In this case you should make sure you are connecting your nodejs application to the correct local port. The code above seems correct just make sure that the tunnel is then from port :8888 to the remote database port, maybe :3607 or whatever the port is.
Otherwise, if your tunnel is not set up properly. There are quite a few tutorials out there explaining how to set an ssh tunnel such as this one :
https://support.cloud.engineyard.com/hc/en-us/articles/205408088-Access-Your-Database-Remotely-Through-an-SSH-Tunnel
Make sure that you also use autossh to set up the tunnel. SSH tunnels are unstable and they tend to fall. Autossh will make sure that the connection is brought back up and that is run when the computer boots up.
https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/

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