MongoDB v4.2.0 Nodejs get started

Install libs

npm i mongodb
npm i saslprep
npm i --save-dev @types/mongodb


const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = 'mongodb://user:[email protected]:27017/database';
// Database Name
const dbName = 'db_ntradebot_dev';

// Create a new MongoClient
const client = new MongoClient(url, {useNewUrlParser: true, useUnifiedTopology: true});

// Use connect method to connect to the Server
client.connect(function (err) {
  assert.equal(null, err);
  console.log("Connected successfully to server");
  const db = client.db(dbName);


Leave a Reply

Your email address will not be published.Required fields are marked *