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