Nodejs : Error get/response localhost - node.js

I'm running a Cakephp app with MAMP on localhost at port 80. I've also Node.js who listen/write on port 4000 with a js script from the Cake app (localhost/client).
When I call Node from js app, it works.
But, when I try to call a Cakephp page (localhost/saveData/123) from Node by http.get(); oder http.request for saving data in database, it crash.
events.js:71
throw arguments[1]; // Unhandled 'error' event
^ Error: connect ECONNREFUSED
at errnoException (net.js:770:11)
at Object.afterConnect [as oncomplete] (net.js:761:19)
Oder
problem with request: connect ECONNREFUSED
I've test width www.google.com, it works. It seems that's the problem is about "localhost".
Could someone help me? :)
EDIT : I've try with 127.0.0.1 too but it doesn't work (for MAMP and Node).
PS : sorry for my english, i'm french :)

Probably you have a local webserver running on port 80. Also programs like Skype can be connected to the port 80.
You can try close Skype and/or Webserver (XAMPP, WAMPP, usbwebserver, etc...).
Listing ports in Cmd.exe
$ netstat -a

Related

SequelizeConnectionRefusedError errno:-111 ECONNREFUSED

I got following exception on node.js express and how can I troubleshoot it?
{"name":"SequelizeConnectionRefusedError","parent":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":6432},"original":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":6432}}
You are getting this exception because your app cannot connect to the database server in localhost and port 6432.
Please make sure your database server is up and running on port 6432 in your localhost

I am getting `getAddrInfo ENOTFOUND localhost` on running simple node server even though localhost is present in /etc/hosts (MacOS El Capitan)

I have a very weird thing happening while setting up and running a normal node js server.
When I run node server.js, I get following error:
Server running at http://localhost:1337/
events.js:160
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND localhost
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
When I open http://localhost:1337/ in my browser, it says page does not exist.
When I run sudo node server.js, it runs fine without any error and I can access my site at https://localhost:1337
Here is my /etc/hosts file:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
My server.js:
// Require what we need
var http = require("http");
// Build the server
var app = http.createServer(function(request, response {
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.end("Hello world!\n");
});
// Start that server, baby
app.listen(1337, "localhost");
console.log("Server running at http://localhost:1337/");
Other Details
OS: Mac OS (El Capitan)
Node JS version: 6.10.3 (installed globally)
NPM version: 4.5.0 (installed globally)
Following are my questions
Why is the above server.js file working with admin access but not as a normal user?
Does globally installed node only work with admin access?
Is there anything else in Mac OS which can affect DNS lookup other than /etc/hosts? I have already flushed my DNS cache and reboot my OS just to make sure that older DNS lookup is not being used.
I have fixed this same error by editing the file /etc/hosts
Added the lines:
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

Run first Nodejs app on cpanel godaddy hosting

I'm trying to run my first Node.js application, but I'm having trouble. This could be an error with the firewall on CPanel, but I'm not sure.
I'm running Node.js version 5.0.0
And this is my js:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write('Open Serverrn');
socket.pipe(socket); });
server.listen(674, 'my.ip.add.ress');
console.log('Server running at http://my.ip.add.ress:674/');
And final : this is my notification :
node test.js
Error is:
Server running at http://my.ip.add.ress:674/
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EACCES my.ip.add.ress:674
at Object.exports._errnoException (util.js:860:11)
at exports._exceptionWithHostPort (util.js:883:20)
at Server._listen2 (net.js:1221:19)
at listen (net.js:1270:10)
at net.js:1379:9
at doNTCallback3 (node.js:461:9)
at process._tickCallback (node.js:367:17)
at Function.Module.runMain (module.js:459:11)
at startup (node.js:136:18)
at node.js:972:3
When I open my console with port 674, it's always loading and timing out after a few seconds. Why is that? Plz help me this issue.
I do not believe GoDaddy has Node.js support, as per this: How to install nodejs application in Godaddy server
Common hosts for Node apps would be:
Digital Ocean, Nodejitsu (owned by GoDaddy anyway), Modulus, Heroku, Joyent, and AWS, I believe.
You need to use port higher than 1024. To bind lower ports you need root privileges or allow program to bind via setcap - can't be implimented at GoDaddy or other shared hosting.

Nodejs in Openshift MongoDB Error

This could probably be very stupid and naive question, but I have tried all my ways to find the solution, but I'm unable to solve. Hope anyone can solve my problem. Thanks in advance.
Recently, I deployed my nodejs application in Open Shift using Mongolab driver for the MongoDB. When I run the application using 'rhc app start -a nodejs', it gives me an ECONNREFUSED error in mongooose.
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
But, when I SSH into the server, go to $OPENSHIFT_REPO_DIR directory and use npm start, the app works very fine.
I connect to the mongodb by defining the URI as shown
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/<dbname>');
I defined the MONGOLAB_URI as an environmental variable in the server.
There would probably be something that I'm missing. But, please bare with this naive.

Unhandled rejection SequelizeConnectionError: connect ENOENT

I am stuck at a point. I am trying to start /connect using command "npm start" but unable to start npm on server.
I am getting this error:
Unhandled rejection SequelizeConnectionError: connect ENOENT
at Handshake._callback (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:63:20)
at Handshake.Sequence.end (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Protocol.handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/Protocol.js:358:14)
at Connection._handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/Connection.js:382:18)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
Apart from this my website work on nodejs & have nginx server configured on server.
Every thing started when I tried to set apache for adding a wordpress blog website. Since nginx already working on port 80. I was trying to set apache on another port so that everything work and ended up with above error. Now my website is not starting at all.
Edit:
My website is running using nodejs. I needed a wordpress blog website to run along and so i checked if there is a scope for apache on my server.
I found that apache along with nginx service was already running and mysql as well.
nginx is essential to run "adminer", a database management tool
Since nginx and apache was running on same ports, i tried to set apache on another port, other than default port.
After that I restarted apache, stopped mysql, stopped nginx and also stopped node
I used pkill node command for stopping node service.
Then restarted everything but got the above error.
I tried many things, and finally reset everything.
Ever since then I am stuck on this error.
Can anyone help?
I finally figured the problem and solved it.
Connect ENOENT means that system is unable to connect to mysql because its path is not correct.
As mentioned in an approved answer from Connect MySQL with Sequelize
Update your models/index.js file with the mentioned code.
To find you mysql socket path go to file here /etc/mysql/my.cnf ( this path may depend on your server). For my case it was /etc/my.cnf. Here you will find the socket path. Now paste this path to the code above and do npm start.
Problem is resolved. :)

Resources