Open QuXiangjie opened 7 months ago
we need download a package called mongoose
npm install mongoose
In the index.js file
import mongoose from 'mongoose' mongoose.connect("database URL")
Then we need to hide the database URL
create a file called .env npm install dotenv in the index.js file
import dotenv from 'dotenv' dotenv.config(); mongoose.connect(process.env.Mongo)
Also in the .gitignore file, we need to add .env
then we can deal with the database connection
mongoose.connect(process.env.mongodburl).then( ()=>{ console.log("Connect to the database"); } ).catch( (err)=>{ console.log(err) } )
we need download a package called mongoose
In the index.js file
Then we need to hide the database URL
create a file called .env npm install dotenv in the index.js file
Also in the .gitignore file, we need to add .env
then we can deal with the database connection