I have a basic script which is test for connecting to database.
When I'm trying to run the script with node Connection.js the script's run, but I don't receive the response in console that successfully connected to the database and as well with that I don't receive any error. It's just looks like the script runs but nothing happens.
On VPS I'm using Ubuntu 18.04. I allowed the IP address and port from my local machine.
Any ideas what's wrong with this one, I was trying to find anything related this topic but unsuccessful
Connection.js
const mongoose = require('mongoose');
var express = require('express');
const router = express.Router();
// this is our MongoDB database
const dbRoute =
'mongodb://username:[email protected]:22/CryptoCurrencies';
mongoose.Promise = global.Promise;
// connects our back end code with the database
mongoose.connect(dbRoute, {
useNewUrlParser: true,
useUnifiedTopology: true
});
let db = mongoose.connection;
db.once('open', () => console.log('connected to the database'));
EDIT1
I edited the code and I 100% sure that I allow on my ubuntu server port 22 but I still can't connect to my VPS with Node
I receive this error - (node:10115) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED
Any ideas on how I can fix this one? Username and password are correct, DB name is also correct, ip address and port as well. Currently I totally don't understand what is wrong. I check tons of resources to solve that and just connect my NodeJS script from local machine to VPS server.
There seems to be some issues with the configuration on server. Please go through these checklist for issues.
bind_ip = 127.0.0.1 for local only, bind_ip = 0.0.0.0 to listen traffic from all network interfaces.) for more details.CryptoCurrencies the one you are connecting to)Check this link on how to configure auth on MongoDB server instance https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With