my code:
const mongoose=require('mongoose');
mongoose.connect('mongodb://localhost:27017/shortner',{
useCreateIndex:true,
useNewUrlParser:true,
useUnifiedTopology:true
}).then(()=>{
console.log("connection is successfull");
}).catch((e)=>{
console.log("no connection ");
});
I tried connecting mongodb with mongoose but its not working. I am getting “no connection” in my console.
I wrote this in other file and required it in my index.js file.Here is code of my index.js file:
const express= require('express');
require("../main/db/conn");
const app=express();
const port= process.env.PORT || 8000;
app.set('view engine','ejs');
app.get('/',(req,res)=>{
res.render('index',{name:'sonai'})
});
app.listen(port,()=>{
console.log("server is starting")
});
Please if anyone can help me with this.