async await mongoose connection 1

async await mongoose connection

(async () => {
  try {
    await mongoose.connect(dbURI, dbOptions)
  } catch (err) {
    console.log('error: ' + err)
  }
})()

Here is what the above code is Doing:
1. We’re importing the mongoose module and assigning it to a variable called mongoose.
2. We’re importing the dbURI and dbOptions variables from the config.js file.
3. We’re creating a new Mongoose connection using the mongoose.connect() method.
4. We’re wrapping the mongoose.connect() method in an async function and calling it immediately.

Similar Posts