×

Html & Html5

The World's best Software Development Study Portal




Node Js MongoDB Connection:



create file in db folder name as conn.js

const mongoose = require ("mongoose")

//use should have mongo db install in your system

mongoose.connect("mongodb://localhost:27017/nodedatabasename", {

useNewUrlParser:true,

useUnifiedTopology:true

}).then(()=>{

console.log("Database Connect");

}).catch((error)=>{

console.log(error);

})
Now connect this DB file in App.js

require("./db/conn");