Connect to MongoDb using mongoose in NODE js
Here is the way, to connect mongodb in NODE js using mongoose module
// first of all require mongoose NODE module
var mongoose = require('mongoose');
// then connect to local mongodb database
var db = mongoose.connect('mongodb://127.0.0.1:27017/test');
//And finally attach a listener to connected event if want to check status/ other
mongoose.connection.once('connected', function() {
console.log("Database Connected")
});
// first of all require mongoose NODE module
var mongoose = require('mongoose');
// then connect to local mongodb database
var db = mongoose.connect('mongodb://127.0.0.1:27017/test');
//And finally attach a listener to connected event if want to check status/ other
mongoose.connection.once('connected', function() {
console.log("Database Connected")
});
Comments
Post a Comment