I got this error when run socket.io in docker - node.js

Error:
events.js:167
node_app_1 | throw er; // Unhandled 'error' event<br>
node_app_1 | ^
node_app_1 | Error: listen EADDRNOTAVAIL 50.177.55.2:3000<br>
node_app_1 | at Server.setupListenHandle [as _listen2] (net.js:1269:19)<br>
node_app_1 | at listenInCluster (net.js:1334:12)<br>
node_app_1 | at GetAddrInfoReqWrap.doListen [as callback] (net.js:1460:7)<br>
node_app_1 | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:62:10)<br>
node_app_1 | Emitted 'error' event at:<br>
node_app_1 | at emitErrorNT (net.js:1313:8)<br>
node_app_1 | at process._tickCallback (internal/process/next_tick.js:63:19)<br>

Update:
Change your socker-io server's IP to 127.0.0.1
Your app is trying to listen on port 3000 and I believe it is already being used.
If you have some other service running on this port, you will either have to change the port of your socket-io server or follow the following process to kill the process that is already listening on port 3000.
Type the following in your terminal,
lsof -i:3000
It will show you the process that is listening to that port. Then you can kill that process using its process ID (PID)
kill -9 <PID>

Related

Getting Error while connecting mongodb to Node.js app using mongoose atlas

I was trying to connect the MongoDB atlas using mongoose but this is the error I'm getting.
[nodemon] starting `node app.js`
node:events:505
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1372:16)
at listenInCluster (node:net:1420:12)
at Server.listen (node:net:1508:7)
at Function.listen (E:\S and P Global Notes_lect\Nodetest\node_modules\express\lib\application.js:635:24)
at E:\S and P Global Notes_lect\Nodetest\app.js:11:97
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1399:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...
First I thought the error was in the password encoding but I solved it then I got this one
You are most likely already running the server in the same port (3000).
Check your processes and terminate the other instance of the node app that is listening on 3000
Check your network to see if port 3000 is already in use by another application
or
Change the port of your node app to listen to another unused port and the error should go away.

Connecting mLab to Node via Mongoose

I am trying to follow this tutorial: https://medium.com/#bryantheastronaut/react-getting-started-the-mern-stack-tutorial-feat-es6-de1a2886be50
I'm stuck because I can't find a way to connect my mLab database to node. I have figured out that the <> around the user name and password need to be removed from the string, but I still can't get it to connect.
mongoose.connect('mongodb://Testerxxx:Testxxx#ds157057.mlab.com:57057/testxxxx');
The log shows the error as:
(node:91198) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
09:37:34 api.1 | events.js:183
09:37:34 api.1 | throw er; // Unhandled 'error' event
09:37:34 api.1 | ^
09:37:34 api.1 | Error: listen EADDRINUSE :::3001
09:37:34 api.1 | at Object._errnoException (util.js:1022:11)
09:37:34 api.1 | at _exceptionWithHostPort (util.js:1044:20)
09:37:34 api.1 | at Server.setupListenHandle [as _listen2] (net.js:1351:14)
09:37:34 api.1 | at listenInCluster (net.js:1392:12)
09:37:34 api.1 | at Server.listen (net.js:1476:7)
When I follow the link to the readme for this error: http://mongoosejs.com/docs/connections.html#use-mongo-client, I can't actually see any instructions that differ from those in the tutorial.
Can anyone see what's wrong with this from. I've used the exact string from the Mongo DB connect page, inserting the mongoose.connect bit at the front.
Can anyone point to more detailed instructions for connecting to mLab?
Another hypothesis:
When I run npm run start-dev, the terminal shows a message that says:
Local: http://localhost:3000/
12:58:52 web.1 | On Your Network: http://10.0.0.2:3000/
12:58:52 web.1 |
However, the page I'm trying to check is port 3001 (per the tutorial). My server.js file also asks for the 3001 port to be used:
var port = process.env.API_PORT || 3001;
Maybe the reason why I can't get a response for the mLab connection is something to do with the difference in ports. If that's the case, I don't understand because, to this point, I have followed the tutorial in the setup.

When running or lifting sails/nodeJS application Error: listen EADDRINUSE

events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Array.async.auto.start [as 0] (/var/www/html/zentiera/node_modules/sails/lib/hooks/http/start.js:29:35)
While using sails js or node js, The error may create difficulties in newbies of technology.
This specially comes when we try to stop the application using (ctrl+z)
and unfortunately the error creates while restarting it
^Z
[1]+ Stopped sails lift
There are 2 methods to recover this situation :
Need to kill the previous port
fuser -k 9002/tcp
Declare a different port number in your application
localhost//config/local.js
port: process.env.PORT || newPortNumber,

Node.js throws the below "events.js:72 throw er; // Unhandled 'error' even"

I am running one .js script and new to the node.js, I am getting below errors:
2014-08-12 23:24:20.986 UTC - Server running at 10.11.6.249:9090
events.js:72
throw er; // Unhandled 'error' event
^ Error: listen EADDRNOTAVAIL
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at net.js:1146:9
at dns.js:72:18
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
Not sure why these errors are I have closed the port 8000 and re-launch app as well, still facing the same issue.
It is not a problem of port (through I don't understand 8000 or 9090) it is a problem of IP address. Either it was changed and is hardcoded, or IP conflict in network. Run it with 127.0.0.1

Port in use when launching Node.js app with Heroku Foreman

I am trying to deploy my node.js app to heroku but when I try to launch it locally using foreman I am getting Error: listen EADDRINUSE. I have run a netstat and grepped for the port nothing else is using it and the server starts without issue when running directly as a node http server.
The app I am trying to deploy is using mongo and redis I am not sure if these components will effect the server starting with Foreman. Does anyone have any suggestions on areas I could look at for potential bugs?
foreman start
01:37:18 web.1 | started with pid 1835
01:37:18 web.1 | /usr/local/foreman/lib/foreman/process.rb:66: warning: Insecure world writable dir /usr/local in PATH, mode 040777
01:37:19 web.1 | events.js:72
01:37:19 web.1 | throw er; // Unhandled 'error' event
01:37:19 web.1 | ^
01:37:19 web.1 | Error: listen EADDRINUSE
01:37:19 web.1 | at errnoException (net.js:863:11)
01:37:19 web.1 | at Server._listen2 (net.js:1008:14)
01:37:19 web.1 | at listen (net.js:1030:10)
01:37:19 web.1 | at Server.listen (net.js:1096:5)
01:37:19 web.1 | at Function.app.listen (/Users/craig/Documents/Sandboxes /xxx/node_modules/express/lib/application.js:535:24)
01:37:19 web.1 | at Object.<anonymous> (/Users/craig/Documents/Sandboxes/xxx/web.js:25:5)
01:37:19 web.1 | at Module._compile (module.js:456:26)
01:37:19 web.1 | at Object.Module._extensions..js (module.js:474:10)
01:37:19 web.1 | at Module.load (module.js:356:32)
01:37:19 web.1 | at Function.Module._load (module.js:312:12)
01:37:19 web.1 | exited with code 8
01:37:19 system | sending SIGTERM to all processes
SIGTERM received
Thanks.
--Additional information--
The procfile just has one entry:
web: node web.js
and I have set the listener up as follows:
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
I just ran into this on OS X. It looks like foreman picks port 5000 by default, which seems to conflict with Bonjour/mDNS/UPNP services. (From what I've read. I haven't taken the time to pick out which it is.)
However, you can change the port that foreman uses in two ways: specify the port on the command line or create a .foreman file with the port number specified there.
Good luck and happy coding!
I had the same issue, Error: listen EADDRINUSE means that a Node server is already running.
Check that you are not running a Node server for the same project locally. If you are working on a GitHub synced project locally (on port 5000 for instance) which is tied to Heroku you cannot run a local Node server for that project as the port will be in use twice.
I was actually running a Node server on a project in a different Terminal window and didn't notice immediately.

Resources