RethinkDB error when connect to live server on AWS - node.js

Connecting to local server is working fine. But i have to maintain one centralized DB for my team. I setup rethinkdb on aws server and have to access this from local from each system in my local project
app.use(function(req,res,next){
r.connect({
host: '55.52.57.59',
port: 28015,
db: 'league'
},function(err,conn){
if (err) throw err;
req['app_conn']=conn;
next();
});
});
what could i do? Please help me!

Check whether you have opened 28015 port on AWS Server or not?

Related

Unable to connect to SQL Server database using mssql and expressjs

I am trying to connect to a SQL Server database from expressjs using mssql, but I keep getting this:
I am following the example from https://www.npmjs.com/package/mssql#connections-1
The code in my app.js is as follows
const config = {
//user: '',
//password: '',
server: 'LAPTOP-A7INMDKJ',
database: 'dbone'
}
sql.on('error', (err)=> {
// error handler
});
sql.connect(config).then(
(pool) =>{
return pool.request()
.query('select * from course');
}).
then(result=> {
console.log('dasdasdsa');
console.log(result);
}).
catch( (err)=>{
console.log(err);
});
I Component services I have this
and in computer management tcp/ip is enabled
What am I doing wrong? I am using Windows authentication for SQL Server.
The normal troubleshooting process is to verify:
SQL Server has TCP/IP enabled and is configured to listen on port 1433 in Configuration Manager.
SQL Server is running and the SQL Server Error log has an entry like Server is listening on [ 'any' <ipv4> 1433].
The Windows Firewall is not blocking inbound TCP connections on port 1433
The client can resolve the SQL Server's hostname correctly
The client can connect over TCP/IP to port 1433 on the SQL Server, eg by powershell's Test-NetConnection -ComputerName [sqlserverhostname] -Port 1433

connect to mongodb in docker from node app in AWS SAM

I am getting errors connecting to mongodb running in a docker container from my Nodejs app running in AWS SAM (used to say "in my host").
I run mongodb like:
$ docker run --name mongo-myapp --rm -d -p 27018:27017 mongo
and I see the results:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab8248d17d2d mongo "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:27018->27017/tcp mongo-myapp
~~I can successfully connect and insert data using clients running on my host like MongoDB Compass and Robo 3T Community Edition, specifying port 27018.~~
When I attempt to connect with this code running on my host, (not in a docker container):
const { MongoClient } = require('mongodb');
const mongoConnection = 'mongodb://127.0.0.1:27018';
MongoClient.connect(mongoConnection, (err, db) => {
if (err) {
console.error("Failed to connect to mongodb server", err);
return reject(err);
}
console.log("Connected successfully to mongodb server");
resolve(db);
});
I always see the error:
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27018
I get the same error using another port with all steps, like 27017.
UPDATE
It turns out my code was not running on the host. It was running in another docker container. I did not realize AWS SAM would put my code into a docker container so I did not mention it in the original question.
Now I run my code with mocha test to make sure it will run on my host, and it connects to the mongo database with no problems.
When I launched a local server using AWS SAM's start-api, I had problems. Perhaps the solution will be to specify a network when starting the mongo container as well as the SAM environment.
Now that the problem is known that the Nodejs code was running within a docker container created by AWS SAM, we can help the Nodejs code connect with Mongodb running in a separate docker container with a port exposed on the host with at least one solution:
Change the connection string to mongodb://host.docker.internal:27018 which helps the code in the container to use a service running on the host.
Install the necessary dependency for mongodb in node.js https://www.npmjs.com/package/mongodb
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://localhost:27018/testdb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
Since you are able to connect from other clients in the same host, I assume that the container is bound to specific external facing ip of the host.
Can you try connecting to the ip of the host instead of 127.0.0.1
Eg: mongodb://external-ip:27018
Though the mapping -p 27018:27017 should bind the port to all ips, you can enforce this by -p 0.0.0.0:27018:27017.

Having trouble setting up Postgres server to accept SSL connections

I'm on a Mac using Postgres.app to run a Postgres server.
I'm connecting to the server in Node.js (code copied from Heroku docs):
pg.defaults.ssl = true;
pg.connect(process.env.DATABASE_URL || 'postgres://localhost:5432/my-project', function(err, client) {
if (err) throw err;
console.log('Connected to postgres! Getting schemas...');
client
.query('SELECT table_schema,table_name FROM information_schema.tables;')
.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
I then followed the instructions here to allow my Postgres server to accept SSL connections. I changed the ssl setting to on in my postgresql.conf file. I also generated the required files, server.key and server.crt.
However, when I run my Node server, I get this error:
Error: The server does not support SSL connections
I ran psql and did show ssl. It returned off. So then I thought that maybe I had the wrong config file...but then I did show config_file and I'm definitely in the right place. What else am I missing?
Very likely you forgot to restart the PostgreSQL server.
In case of problems, set log_connections = on and check the PostgreSQL server log.

Nodejs net does not throw error when trying to connect to a host thats not listening

I'm trying to test whether a remote host is listening or not using Node.js net module:
var net = require('net')
var client = net.connect({port:3000, host:remoteHostIP},function(){
});
client.on('error', function(err){
console.log("Error: "+err.message);
});
I would expect that net.connect would throw an error if it can't connect but that's not the case.
Also client.on('error') does not throw an error.
How can I check if the connection has been possible?
It will throw an error when the connection times out which is about one minute of no data transfer.
Error: connect ETIMEDOUT <ip>:3000
Use client.setTimeout() to fire a callback if there's no activity within the allocated time.
The code posted in the question works fine:
node app.js
Error: connect ECONNREFUSED
The issue has been caused by a Virtualbox VM for Docker (running on the developer machine) which had portforwarding configured for port 3000 and grabbed the net connect request for localhost.

Node connecting to Mongodb in my VPS with port 27017, no if I change the port

I've got a Digital Ocean VPS, and followed their tutorial:
link
It's working the app.js and connecting to the database.
Here is the code of the apps file:
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
}
db.close();
});
But if I change the port 127.0.0.1:27017 to 127.0.0.1:3500 the one I want to connect, it's not working.
Here is my ufw
ufw allow 22/tcp
ufw allow 3500/tcp
ufw allow 80/tcp
ufw allow 27017/tcp
Any help?
Thank you
Man, you did a bad thing. You opened MongoDB to whole world. If your node.js app is on the same server with MongoDb, then no reasons to open 27017 & 3500 for internet. Close these ports ASAP.
Why do you think that you changed mongoDb port? Please show mongoDb config file with port configuration row. Also after you changed the mongodb config file it requires restart mongodb servic/daemon.

Resources