NodeJS Mongoose Library
Connect to MongoDB Using Mongoose
First, install Mongoose with:
Then, add it to server.js as dependencies:
Create a model and connect to the database:
Next, start MongoDB and run server.js using node server.js
To check if we have successfully connected to the database, we can use the events open, error from the mongoose.connection object.