DEV Community

Rittwick Bhabak
Rittwick Bhabak

Posted on

#2 Installing MongoDB Locally & connecting to MongoDB

  1. npm init -- to track the dependencies.
  2. Install mongoose npm install mongoose --save
  3. Connecting to database: Mongoose do not automatically knows about database. we've to tell it explicitly.
//connection.js
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/testaroo');

mongoose.connection.once('open', function(){
    console.log('Connection is made');
}).on('error', function(error){
    console.log('Connection error', error);
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)