Coonection time out error comes again and again on MongoDB - javascript

My code gives time out error when connecting to the database.
The strange part is that yesterday it was connecting perfectly, the same code.
look:
const uri = "mongodb+srv://<MyUser>:<MyPassword>#cluster0.ot7abmk.mongodb.net/?retryWrites=true&w=majority"
const client = new MongoClient(uri);
async function run(){
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// client.db("gastos").createCollection("gastos")
console.log("Connected successfully to server");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
My package.json:
"name": "controle-de-gastos-full-stack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/G4rutti/controle-de-gastos-full-stack.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/G4rutti/controle-de-gastos-full-stack/issues"
},
"homepage": "https://github.com/G4rutti/controle-de-gastos-full-stack#readme",
"dependencies": {
"mongodb": "5.0"
}
}
This is the error you are getting. I personally have no idea what it is, since yesterday, the same code was working.
Error:
MongoServerSelectionError: connection <monitor> to 18.231.18.253:27017 closed
at Timeout._onTimeout (MyDir)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-kac6ni2-shard-00-02.ot7abmk.mongodb.net:27017' => [ServerDescription],
'ac-kac6ni2-shard-00-00.ot7abmk.mongodb.net:27017' => [ServerDescription],
'ac-kac6ni2-shard-00-01.ot7abmk.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-hqwzt1-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}

Related

I try to use es6-module in my project and I have an error when I will migrate my migration, how to solve error like this?

Here is my config code, I made this using sequelize-cli and then I try to change the code using es6-module. Is there something wrong with this code ?
import "dotenv/config.js";
const {
DB_HOST,
DB_USER,
DB_PASSWORD,
DB_NAME
} = process.env;
export default {
"development": {
"username": DB_USER,
"password": DB_PASSWORD,
"database": DB_NAME,
"host": DB_HOST,
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": DB_USER,
"password": DB_PASSWORD,
"database": DB_NAME,
"host": DB_HOST,
"dialect": "mysql"
}
}
and this my package.json. I have tried to looking for the solution for this problem but I still cant to solve this, anyone can help me ?
{
"name": "api_skripsi",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.0",
"express": "^4.17.3",
"mysql2": "^2.3.3",
"sequelize": "^6.17.0"
},
"devDependencies": {
"husky": "^7.0.4"
}
}

SQLITE_CANTOPEN: unable to open database file electronjs

I am facing the sqlite db issue in production mode.
Its working fine on using npm start (on normally run) but not working when i try to create release file for linux using electron-builder build --linux
my package.json file is as follows
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"dist": "electron-builder"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^13.1.0",
"electron-packager": "^15.2.0"
},
"build": {
"appId": "pkg.dmo.com",
"productName": "sample",
"copyright": "Copyright",
"mac": {
"target": [
"zip"
],
"publish": [
"github"
]
},
"win": {
"target": [
"nsis"
]
},
"linux": {
"target": [
"AppImage",
"tar.gz"
]
},
"dmg": {
"icon": "build/icon.icns"
}
},
"dependencies": {
"jquery": "^3.6.0",
"sqlite3": "^5.0.2"
}
}
and my sqlite code is as follows:
let $ = (jQuery = require("jquery"));
const sqlite3 = require("sqlite3").verbose();
const path = require('path')
const dbPath = path.join(__dirname, 'testdb.db');
$( document ).ready(function() {
let db = new sqlite3.Database(
dbPath,
sqlite3.OPEN_READWRITE,
(err) => {
if (err) {
console.error(err.message);
}
}
);
db.each("SELECT * FROM Mouse", [], function (err, row) {
console.log("helli");
if (err) {
console.log(err);
return console.error(err.message);
}
console.log("mouse row is =>", row);
});
});
i have tried
var db = new sqlite3.Database( path.resolve(__dirname, 'testdb.db') );
and
var db = new sqlite3.Database( path.join(__dirname,
'testdb.db').replace('/app.asar', '') );
still getting same error in exe but working on local(when npm start)

Electron application in production throw: error Command failed: node index.js but in development works fine

Have you ever had this issue:
I was working on my app in development, and everything works fine, but when I created the executable and try to click on my button throw this error:
This the code that is executed when I press my button:
const { exec } = require("child_process");
let myBtn = document.getElementById('my-btn');
myBtn.addEventListener('click', (e) => {
e.preventDefault();
exec("node index.js", (error, data, getter) => {
if(error){
console.log("error",error.message);
return;
}
if(getter){
console.log("data",data);
return;
}
console.log("data",data);
});
});
This the error:
Not recognize the module node and my file index.js
error Command failed: node index.js
internal/modules/cjs/loader.js:1068
throw err;
^
Error: Cannot find module '/home/myUser/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
at Function.Module._load (internal/modules/cjs/loader.js:911:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is my package.json
{
"name": "app",
"version": "1.0.0",
"description": "description",
"main": "main.js",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"puppeteer": "^9.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "^12.0.5"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
}
}

npm gulp 800a138f javascript error

When i put 'gulp hello' in cmd i got this error 800a138f javascript object expected error
This is my package.json file
`{
"name": "goes",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node gulp.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.9.1"
}
}`
This is gulp.js
`var gulp = require('gulp');
gulp.task('hello', function() {
console.log('Hello Zell');
});`

request.ref is not a function

I ran the node code on this site https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html by using:
node app
I get the following error:
TypeError: request.ref is not a function.
which corresponds to the following line:
sendNotificationToUser("username","new msg",function() {request.ref().remove();} );
This is my package.json file:
{
"name": "myApp",
"version": "1.0.1",
"description": "listen for addition of msgs",
"main": "app.js",
"scripts": {
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud app deploy"
},
"author": "my name",
"engines": {
"node": "~4.2"
},
"license": "ISC",
"dependencies": {
"firebase": "^3.2.1",
"request": "^2.74.0"
}
}
There are indeed some typos in the code. The actual version I run with uses this to remove the messages that have been sent:
requestSnapshot.ref.remove();
The entire listenForNotificationRequests method (in case I made any other edit mistakes while porting to the blog):
function listenForNotificationRequests() {
var requests = ref.child('notificationRequests');
requests.on('child_added', function(requestSnapshot) {
var request = requestSnapshot.val();
sendNotificationToUser(
request.username,
request.message,
function() {
requestSnapshot.ref.remove();
}
);
}, function(error) {
console.error(error);
});
};

Categories

Resources