How do you connect Express to MongoDB with Mongoose?

MongoDB and Mongoose · Freshers

Model answer

Call await mongoose.connect(process.env.MONGODB_URI) once when the app starts, then start listening only after it connects, or handle connection errors. Keep the URI in an environment variable, and use MongoDB Atlas or a server you control.

Learn this topic

Connect Express to MongoDB with Mongoose in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions