Let's set up a simple app with the MongoDB driver to perform a simple connection check. In this test, we will use the Backpack build system that we covered in the previous chapter to run our test. So, let's get it started with the following steps:
- Install the MongoDB driver as shown in the previous section, followed by Backpack and cross-env:
$ npm i backpack-core
$ npm i cross-env
- Create a /src/ folder as the default entry directory and create an index.js file in it, and then import the MongoDB driver and the Assert module from Node.js as follows:
// src/index.js
import { MongoClient } from 'mongodb'
import assert from 'assert'
const url = 'mongodb://localhost:27017'
const dbName = 'nuxt-app'
In this step, we should also provide the MongoDB connection details: the MongoDB server default address, which is mongodb://localhost:27017, and the database that we want to connect...