1//using mongoose
2npm i mongoose
3
4const mongoose = require("mongoose");
5
6mongoose
7 .connect(
8 "your mongodb URI",
9 {
10 useNewUrlParser: true,
11 useCreateIndex: true,
12 useFindAndModify: false,
13 useUnifiedTopology: true,
14 }
15 )
16 .then(() => console.log("mongodb connected"))
17 .catch((err) => {
18 console.err(err.message);
19 process.exit(1);
20 });