xxxxxxxxxx
// Get dotenv and Mongodb from NPM
// Create a ".env" file and add the variables
// Require both mongodb and dotenv
const dotenv = require('dotenv');
dotenv.config()
const { MongoClient } = require('mongodb')
// The mongodb connection string
const client = new MongoClient(process.env.CONNECTIONSTRING);
// Database Name
const dbName = 'ComplexApp';
// connect to the db and start your app / listen to the app
async function start (){
await client.connect()
module.exports = client.db(dbName)
const app = require('./app')
app.listen(process.env.PORT)
}
// Call the function
start()