expressjs connect to mongodb code example
Example: connect mongo to express api
//using mongoose
npm i mongoose
const mongoose = require("mongoose");
mongoose
.connect(
"your mongodb URI",
{
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
}
)
.then(() => console.log("mongodb connected"))
.catch((err) => {
console.err(err.message);
process.exit(1);
});