pablocattaneo
1/6/2019 - 12:42 PM

How to connect mongodb driver to a localhost database?

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

mongodb.connect('mongodb://localhost/database_name', {useNewUrlParser: true })
  .then(( client ) => {
    console.log('Connected!')
    client.close()
  })
  .catch(err => {
    console.log(err)
  })