'Node.js database connectivity with MongoDB?

I create my new Project clientside i am using Angular6 and Serverside i use Node.js now i want to make database connectivity node.js with MongoDB. Previously i used Mysql database, then i heard about MongoDB database but i dont know how to connect MongoDB database with Node.js kindly help me how to connect node.js with MongoDB(which packages i have to install all that and then how to connect,for that good websites and links are available kinly share)

in mysql i used phpmyadmin is used, for mongoDB what is used ?

app.js(node.js)

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
   next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;


Solution 1:[1]

Mongoose is a npm module that is widely used for connecting to MongoDB. You can use it with local db or mlab.com.

https://mongoosejs.com/

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

Solution 2:[2]

mongoose = require("mongoose");

const DB = () => {
    mongoose.connect("mongodb://localhost:27017/crud", (err) => {
        if (!err) {
            console.log('connection established');
        } else {
            console.log(' Not connection');
        }
    });
}
module.exports = DB;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karan Bhomia
Solution 2 Hussain