Home > Enterprise >  Send a message to console about connection established or refused
Send a message to console about connection established or refused

Time:03-30

I'm working on a NodeJS Express Mongo exercise, the lines that I'm using to connect to MongoDB are these ones:

const app = express();
const store = new MongoDBStore({
  uri: MONGODB_URI,
  collection: "sessions",
});

The connection is working but I would like to send a console.log with the output, either "connection established" or "couldn't connect". Do you have any hints how can I accomplish this task?

Thanks a lot

CodePudding user response:

You tried to use MongoClient.connect method? You can pass a callback with a console.log to inform the status of the connection. You can see about this here: https://www.tabnine.com/code/javascript/functions/mongodb/MongoClient

  • Related