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:password@ip.adress: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.