I'm trying to make a connection to MongoDB using Mongoose. But it does neither throws a error nor connects to the database. Following is my code.
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
const mongoose = require('mongoose');
console.log('Hi, there!!');
mongoose.connect('mongodb://localhost:27017/db_name', (err) => {
console.log('Callback called');
if(err) throw err;
console.log('Connected to database');
})
In the above code none of the console.log inside the callback do happen. But any placed outside the mongoose connect do work like console.log('Hi, there!!')
via Abhinav Vudya
No comments:
Post a Comment