arangojs collections() errors return - arangodb

I'm totally green with it all. Sorry, but I cant get this thing to work at all node.js + arangojs >
const myColl = async () => {//new Promise((resolve, reject) => {
try {
const db = await new Database({
url: "http://localhost:8529",
databaseName: "testDB",
auth: {username: "userTest", password: "userTest"},
});
console.log(db)
try {
let collection = await db.collections();
console.log(collection);
} catch (err) {
console.log(err);
}
} catch (err) {
console.log("Failed to login db ", err)
return
}
}
myColl()
I just end up with :
Database {_analyzers: Map(0), _collections: Map(0), _graphs: Map(0), _views: Map(0), _connection: Connection, ...}
icAccountController.js:23
Error: connect ECONNREFUSED ::1:8529 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1237:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {errno: -4078, code: "ECONNREFUSED", syscall: "connect", address: "::1", port: 8529, ...}

Related

MongoServerSelectionError: connect ECONNREFUSED ::1:27017

I am using mongo 5.0.1 and node 17.2.0
this is my code
If I connect want to connect with atlas with this code it runs successfully but when I try to connect with the local Database it gives this error.
const { MongoClient } = require("mongodb");
async function main(){
const uri = "mongodb://localhost:27017";
const client = new MongoClient(uri);
try{
await client.connect();
await listDatabases(client);
} catch (e){
console.error(e);
} finally {
await client.close();
}
}
main().catch(console.error);
async function listDatabases(client) {
databasesList = await client.db().admin().listDatabases();
console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};
This is the error I am getting.
MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (D:\web development\nodeDemo\node_modules\mongodb\lib\sdam\topology.js:330:38)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
}
}
use this as your uri
const uri = "mongodb://127.0.0.1:27017";
I solved this by enabling the IPv6 in the mongodb.config
more info here https://www.mongodb.com/docs/manual/reference/configuration-options/#mongodb-setting-net.ipv6
Use this URL:
mongodb://127.0.0.1:27017
Instead of:
mongodb://localhost:27017

Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 node.js

Trying to connect to DynamoDB and getting this error
I am trying to use this db to test some Telegram bots but now its not essential, cause i just can't find any information how to fix this problem, mb i am stupid, but...
Code:
var AWS = require("aws-sdk");
let awsConfig = {
"region": "eu-central-1",
"endpoint": "http://dynamodb.eu-central-1.amazonaws.com",
"accessKeyId": "my_access_key",
"secretAccesKey": "my_secret_access_key"
}
AWS.config.update(awsConfig);
let docClient = new AWS.DynamoDB.DocumentClient();
let fetchOneByKey = function ()
{
var params =
{
TableName: "users",
Key: {
"id": 132
}
};
docClient.get(params, function (err, data) {
if(err){
console.log("error: " + JSON.stringify(err, null, 2));
}
else
{
console.log("success: " + JSON.stringify(data, null, 2));
}
})
}
fetchOneByKey();
Tried some solutions from here, but nothing helped
Tried another solution:
let db = new AWS.DynamoDB({apiVersion: '2014-12-04'});
db.listTables({}, function(err, data) { // 2
console.log(data);
console.log(err);
});
Catched this
data:
null
err:
Error: connect ENETUNREACH 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: -4062,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: {
message: 'Could not load credentials from any providers',
errno: -4062,
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: {
message: 'EC2 Metadata roleName request returned error',
errno: -4062,
code: 'ENETUNREACH',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2021-04-15T23:15:09.312Z,
originalError: [Object]
}
}
}

ETIMEDOUT while using mysql2 with Express on AWS Lambda

I am using mysql2 package with the Express Framework, deployed over AWS Lamda. I have the provisioned concurrency set to 3 for Aws Lambda.
I am not directly connecting to MySQL. I have RDS Proxy in between.
I am getting the following error, randomly.
{
"errorType": "Error",
"errorMessage": "connect ETIMEDOUT",
"code": "ETIMEDOUT",
"errorno": "ETIMEDOUT",
"syscall": "connect",
"fatal": true,
"stack": [
"Error: connect ETIMEDOUT",
" at Connection._handleTimeoutError (/var/task/node_modules/mysql2/lib/connection.js:178:17)",
" at listOnTimeout (internal/timers.js:554:17)",
" at processTimers (internal/timers.js:497:7)"
]
}
Following is what my code looks like:
var AWS = require("aws-sdk");
const mysql = require('mysql2');
class DBConnection {
constructor() {
var signer = new AWS.RDS.Signer({
region: 'us-east-1',
hostname: process.env.DB_HOST,
port: 3306,
username: process.env.DB_USER
});
let connectionConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
database: process.env.DB_NAME,
ssl: 'Amazon RDS',
authPlugins: { mysql_clear_password: () => () => signer.getAuthToken() }
};
this.db = mysql.createConnection(connectionConfig);
}
query = async (sql, values) => {
return new Promise((resolve, reject) => {
this.db.execute(sql, values, (error, result) => {
if (error) {
reject(error);
return;
}
resolve(result);
});
});
}
}
module.exports = new DBConnection().query;
const results = await query('SELECT COUNT(*) AS total_listens FROM analytics WHERE event_name="PLAYED"');
Any clue where the issue can be?
With AWS Lambda function it's better to use mysql.createPool instead of mysql.createconnection. I don't know what's the specific reason but using mysql.createconnection instead of mysql.createPool has caused problems for me as well. It's also necessary to release the connection when the query goes successful.

Can't connect to MongoDB with Nodejs

I am using Node js to try to connect to MongoDB. Here are the related code snippets:
{
"port": 3001,
"appPort": 8080,
"host": "localhost:3001",
"protocol": "http",
"allowedOrigins": ["*"],
"domain": "http://localhost:3001",
"basePath": "",
"mongo": "mongodb://100.10.10.10:27017/database",
"mongoConfig": "",
"mongoCA": "",
"mongoSecret": "--- change me now ---"
}
MongoClient.connect(dbUrl, {useUnifiedTopology: true}, function(err, client) {
if (err) {
console.log(err);
debug.db(`Connection Error: ${err}`);
unlock(function() {
throw new Error(`Could not connect to the given Database for server updates: ${dbUrl}.`);
});
}
db = client.db(client.s.options.dbName);
debug.db('Connection successful');
}
When I use 'npm start' to start the server, I got this error:
MongoServerSelectionError: connect EACCES 100.10.10.10:27017
at Timeout._onTimeout (formio\node_modules\mongodb\lib\core\sdam\topology.js:438:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
reason: TopologyDescription {
type: 'Unknown',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map { '100.10.10.10:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
I have tried to enable/disable the firewall but the results still don't change. Could you help me fix it?
Thanks
More information about the repository:
https://github.com/formio/formio
https://github.com/Jobin-S/shopping-cart/blob/master/config/connection.js
please look this repository you can see the example.
Make an config file and require it in app.js
const mongoClient = require('mongodb').MongoClient
const state ={
db:null
}
module.exports.connect = (done) => {
const url = 'mongodb://localhost:27017';
const dbName = 'shopping';
mongoClient.connect(url,{ useUnifiedTopology: true }, (err, data) => {
if(err) return done(err)
state.db = data.db(dbName)
done()
})
}
module.exports.get = function(){
return state.db
}
after making this config file.
require config file and require in app.js file and write the code below
var db = require('./config/connection')
db.connect((err)=>{
if(!err) console.log("Database connected successfully");
else console.log(`Connection Error: ${err}`);
})
after that you can use database in any file.
const db = require('../config/connection')
addProduct: (product) => {
return new Promise((resolve, reject) => {
product.Price = parseInt(product.Price)
db.get().collection(collection_name).insertOne(product).then((data) => {
resolve(data.ops[0]._id)
})
})
}

Firebase Cloud Functions Error: connect ECONNREFUSED

I am trying to create a Kik Messenger bot according to their API using Firebase Cloud Functions. I am using Blaze Plan. I am trying to reply to a message that my bot received. I can receive messages on my API but when I try to reply to them I get an error. An error is not from the request callback. I see the error on Firebase Console.
Error: connect ECONNREFUSED 72.14.246.44:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '72.14.246.44',
port: 443
Requests to the Kik Messenger API works on local and remote node/express app. I tried to use kik-node on Cloud Functions but it gave the same result. What I have discovered so far is that https://auth.kik.com resolves to Amazon and https://api.kik.com resolves to Google Hosting. I think they are also using Firebase Cloud Functions for their API. Can it be possible that they are blocked inbound requests? Here is the sample code of what I tried.
exports.messagepost = functions.https.onRequest((req, res) => {
// Gives the error below
// {
// Error: connect ECONNREFUSED 72.14.246.44:443
// at Object.exports._errnoException (util.js:1018:11)
// at exports._exceptionWithHostPort (util.js:1041:20)
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
// code: 'ECONNREFUSED',
// errno: 'ECONNREFUSED',
// syscall: 'connect',
// address: '72.14.246.44',
// port: 443
// }
request.post({
uri: 'https://api.kik.com/v1/message',
body: JSON.stringify({
foo: 'bar'
}),
json: true,
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
},
headers: {
'Content-Type' : 'application/json'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.messageget = functions.https.onRequest((req, res) => {
// Gives the error below
// {
// Error: connect ECONNREFUSED 72.14.246.44:443
// at Object.exports._errnoException (util.js:1018:11)
// at exports._exceptionWithHostPort (util.js:1041:20)
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
// code: 'ECONNREFUSED',
// errno: 'ECONNREFUSED',
// syscall: 'connect',
// address: '72.14.246.44',
// port: 443
// }
request.get({
uri: 'https://api.kik.com/v1/message',
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.verificationget = functions.https.onRequest((req, res) => {
// Runs with no errors
request.get({
uri: 'https://auth.kik.com/verification/v1/check',
qs: {
u: 'username',
d: 'hostname',
debug: true
},
body: JSON.stringify({ data: 'debugsigneddata' }),
headers: {
'Content-Type' : 'application/json' ,
'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
},
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
exports.verificationpost = functions.https.onRequest((req, res) => {
// Runs with no errors
request.post({
uri: 'https://auth.kik.com/verification/v1/check',
qs: {
u: 'username',
d: 'hostname',
debug: true
},
body: JSON.stringify({ data: 'debugsigneddata' }),
headers: {
'Content-Type' : 'application/json' ,
'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
},
auth:{
user:'{API_USER}',
pass:'{API_KEY}'
}
}, (error, response) => {
if (error) console.error(error);
else console.log('Response: ', response.headers);
res.status(200).end('OK');
});
});
I ran into a similar issue while implementing an OAuth2 token exchange using cloud functions instead of running a dedicated server.
This might not help the OP but to fix this error in my case, I had to add the https:// protocol to my post URL as it was missing.
If others run into this issue it might be worth checking your POST url is written correctly.

Resources