0

I've a problem with my database connection using MongoDB. I'm trying to log my database conenction in my JS server script, but i do not see any logging message in terminal. I used following code:

const express = require('express');
const cors = require('cors');
const db = require('monk')('localhost/meower');


db.then(() => {
    console.log('Connected correctly to server'); //NOT ABLE TO SEE THIS MESSAGE
})



const app = express();


app.use(cors());
app.use(express.json());

app.listen(5000, () => {
    console.log("Listening on http://localhost:5000/");
});

After a while following message appears in the terminal:

Listening on http://localhost:5000/ (node:27408) UnhandledPromiseRejectionWarning: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 at Timeout._onTimeout

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict

DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

``

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "mongodb": "^3.6.3",
    "monk": "^7.3.2",
    "morgan": "^1.10.0",
    "nodemon": "^2.0.6"
  }
}
Anjimlio
  • 15
  • 6

0 Answers0