Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic MongoDB Connection with NodeJS
const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient
const connectionURL = 'mongodb://'
const databaseName = 'customDatabaseName'
MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) => {
if (error) {
return console.log('Unable to connect to database!')
const db = client.db(databaseName)
name: 'Kermin',
age: 32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment