How to set remote connection to database via Mongojs - javascript

i need set remote connection to MongoDB, but i need make it via mongojs.
var docdbconn = mongojs('mongodb+srv://mylogin:mypassword#cluster0-m1s1a.mongodb.net/nameofdatabase?retryWrites=true');
and usually i get next error:
MongoError: failed to connect to server [cluster0-m1s1a.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0-m1s1a.mongodb.net cluster0-m1s1a.mongodb.net:27017]

are you sure the port provided is the right one, if there is no port specified related to the doc it seems like the port 27017 is setted by default. Maybe you're remote database isn't on this port and you need in your connection string to manually specify it.

I found a solution, so i used another string connection for MongoDB 3.4+ and it helped me.
var docdbconn = mongojs("mongodb://nickname:password#cluster0-shard-00-00-m1s1a.mongodb.net:27017,cluster0-shard-00-01-m1s1a.mongodb.net:27017,cluster0-shard-00-02-m1s1a.mongodb.net:27017/databasename?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true");

Related

Mongodb bind multiple ips

I'm using mongodb v4.2.3 for ubuntu, and i'm trying to bind localhost and my public ip, but i get an error every time i reload mongodb afther editing the configuration file.
bind_ip = 127.0.0.1
port = 27017
the error while restarting mongodb:
Job for mongodb.service failed because the control process exited with error code.
See "systemctl status mongodb.service" and "journalctl -xe" for details.
Solved.
bind_ip = 127.0.0.1
For single ip, because it's interpreted as number
bind_ip = "127.0.0.1,xxx.xxx.xxx.xxx"
For multiple ip, because it's interpreted as string

Node.JS MySql Module - Cannot Connect to Any Database - ECONNRESET

I'm trying to use the mysql module to connect to my database. But everytime, I get the following error: read eCONNRESET There is problem. (Note, that last part is from my console log. See below.)
I don't think this is a problem with database security settings. I've been trying to connect to my new database (hosted on AWS) for the last several days with no luck. Then, just now I attempted to connect to an Azure database that has been running smoothly for a couple years. Same problem: read eCONNRESET.
By the way, if I randomly change the host string to something invalid, my code returns an error saying the host wasn't found. So that tells me it's working to some extent.
I'm very new to the coding world and need all the help I can get.
Here's my code:
console.log('starting Launch');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '....windows.net',
user : 'test',
password : 'test',
port : '1433'
})
console.log('step2')
connection.connect(function (err) {
if (!err)
console.log("conncetd");
else
console.log(err + "There is problem");
});
Copy full error message.
Check connectivity to your DB instance, use nmap (linux) or telnet (windows). If you can't reach host - check your local machine and server firewall, restrictions. If you can, go to 2.
Try to use different MySQL client, MySQL WorkBench, HeidiSQL, DBeaver.
If you can't - than something wrong with MySQL configuration. If you can, go to 3.
Copy info about: OS, node version, mysql module version.
you could try
mysql.createPool({});
instead of
mysql.createConnection({})

WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I am new to WebRTC and WebSockets and was following this tutorial to create a WebRTC demo project, but I am unable to create a WebSocket connection. I have followed the same steps as mentioned in the project.
His project is running on port 8080 and he mentioned ws://localhost:9090. My project is running on port 8081, but I copied his URL ws://localhost:9090 because I didn't know the significance of 9090 and I received this error and my server is node.js. i changed local host to 8081 as well but then i am getting hand shake error.
WebSocket connection to 'ws://localhost:9090/' failed: Error in
connection establishment: net::ERR_CONNECTION_REFUSED.
Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server).
However the same should work fine with Firefox.
You need to use ws://yourIp:9090/, where yourIP is like 192.168.?.?.
Usually WebRTC requires a secure connection (that is https).
The error you have got is due to TLS/SSL certificates occupied, may be they are not properly configured in your project.
Provide a valid TLS/SSL certificate and also configure it correctly in project, then it will work without the above error.
try to change the port to 8080
const ws = new WebSocket('ws://localhost:8080/chat')
I guess this is a generic websocket issue.
Change the url to a dynamic name using the built-in location.host variable and change the protocol to secure websocket wss if you have set-up the TLS:
const ws = new WebSocket("wss://" + location.host + "/")
Port 9090 is used by reactotron. Probably you are using it in your project and your app cannot connect with reactotron because it is closed. Just open reactotron and the error will disappear.
also you could easily change the mappings of IP addresses to host names,
on windows go to C:\Windows\System32\drivers\etc\hosts and uncomment this line
127.0.0.1 localhost
save and restart.
WebSocket connection to 'ws://localhost:8080/' failed
Must ensure server file is running
I git this above problem
maybe you forgot to start websocket server, check it again, with configuration in my project, run:
php artisan websocket:init

Error: listen EADDRNOTAVAIL 0.0.0.0:3000 [duplicate]

I installed Nginx and Node.js in my server.
When I try run my node.js file, I get an error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:614:11)
at Array.0 (net.js:689:28)
at EventEmitter._tickCallback (node.js:192:40)
How can I fix this problem?
Thanks!
I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.
I had my HOST environmental variable pointing to a static IP, and my Node server was listening to that address. At some point when my router recycled, it started assigning my machine a new IP, and I started getting the error you posted. It was fixed by changing the address my server was listening to.
My config:
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
http.createServer(app).listen(app.get('port'), app.get('host'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Make sure your host is hitting your machine. In any case, the loopback, as #miltonb suggested, should always work:
app.set('host', '127.0.0.1');
I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:670:11)
at Array.0 (net.js:756:28)
at EventEmitter._tickCallback (node.js:190:38)
Try changing the [hostname] parameter to localhost:
var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');
I was getting the same error, and then I changed the port and worked
Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.
For me, the issue was that the IP that I wrote simply didn't exists :) usually at home I have a 192.168.x.x IP, and after a restart I had a different address ... when I tried to gulp serve my app - it had a config with the old IP ....
as always 127.0.0.1 will work, but when you want to verify your website with other devices, you want to use the external IP 192.168.x.x ... or similar.
Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error
Error: listen EADDRNOTAVAIL
hope this helps.
For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});
works for me.
it also generic for debug by localhost and your local ip without any changes.
This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen and still busy adding the new ipv6 address.
Using an execSync [see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options] to call 'sleep' for a 2 second pause seems to allow listen to not error with Error: listen EADDRNOTAVAIL.
[It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.]
Check your ip ipconfig adress and add any port 3004 for example.
Code below finally work for me. In case if you want to access this server from other device in your network. Or just set local host ip to 127.0.0.1 and get access from your device.
var server = require('http').createServer(app);
server.listen(3004, '192.168.x.x', function () {
console.log("Listening on port 3000!");
});
In my case, I fixed it by checking the directory /tasks/options
I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.

listen EADDRNOTAVAIL error in Node.js

I installed Nginx and Node.js in my server.
When I try run my node.js file, I get an error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:614:11)
at Array.0 (net.js:689:28)
at EventEmitter._tickCallback (node.js:192:40)
How can I fix this problem?
Thanks!
I had this issue, and I thought it was a port issue, but it turned out to be an IP issue.
I had my HOST environmental variable pointing to a static IP, and my Node server was listening to that address. At some point when my router recycled, it started assigning my machine a new IP, and I started getting the error you posted. It was fixed by changing the address my server was listening to.
My config:
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
http.createServer(app).listen(app.get('port'), app.get('host'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Make sure your host is hitting your machine. In any case, the loopback, as #miltonb suggested, should always work:
app.set('host', '127.0.0.1');
I think you need a bit more context like some of your code. I am guessing you are starting to listen on a web server or a socket? Based on that assumption, I get something similar when I run a basic web server on my test server unless I run using localhost.
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL
at errnoException (net.js:670:11)
at Array.0 (net.js:756:28)
at EventEmitter._tickCallback (node.js:190:38)
Try changing the [hostname] parameter to localhost:
var http = require('http');
http.createServer( function ).listen(8000, '127.0.0.1');
I was getting the same error, and then I changed the port and worked
Could it be that node was already running a server? I received a similar error and found this while troubleshooting. Shutting down the previous node server solved my problem.
For me, the issue was that the IP that I wrote simply didn't exists :) usually at home I have a 192.168.x.x IP, and after a restart I had a different address ... when I tried to gulp serve my app - it had a config with the old IP ....
as always 127.0.0.1 will work, but when you want to verify your website with other devices, you want to use the external IP 192.168.x.x ... or similar.
Most of the time it would be the IP address or the hostname. The reason being, node js takes that as the key item to start the server. if there is a conflict or incorrect ip address, it cribs with this error
Error: listen EADDRNOTAVAIL
hope this helps.
For me , i had the same error , and when i check my configuration , i found that host=127.0.0.0 which raises error because it should be 127.0.0.1 instead of 127.0.0.0
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || 'localhost');
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('host') + ':' + app.get('port'));
});
works for me.
it also generic for debug by localhost and your local ip without any changes.
This also will occur while 'ip addr add i:p:v:6' is still in limbo or something (just executed/ing), and the interface is I presume not totally ready to listen and still busy adding the new ipv6 address.
Using an execSync [see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options] to call 'sleep' for a 2 second pause seems to allow listen to not error with Error: listen EADDRNOTAVAIL.
[It's really a bug I think in NodeJS 7.4.0 on Ubuntu because this doesn't happen with ipv4 address creation at the instant before usage/listen connection.]
Check your ip ipconfig adress and add any port 3004 for example.
Code below finally work for me. In case if you want to access this server from other device in your network. Or just set local host ip to 127.0.0.1 and get access from your device.
var server = require('http').createServer(app);
server.listen(3004, '192.168.x.x', function () {
console.log("Listening on port 3000!");
});
In my case, I fixed it by checking the directory /tasks/options
I found connect.js file which had static IP address which was incorrect. I just changed it to the correct one and it worked.

Categories

Resources