Categories
JavaScript Answers

How to get Mongoose connect error with Node?

Spread the love

To get Mongoose connect error with Node, we call connect with a callback as the 2nd argument.

For instance, we write

mongoose.connect("mongodb://localhost/dbname", (err) => {
  if (err) {
    throw err;
  }
});

to call connect with a callback as the 2nd argument.

We get connection errors from err if there’s any.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *