im facing this error in node.js, wen i try to add to the db. i have downloaded “controller”: “^1.0.0”, “cors”: “^2.8.5”, “dao”: “^0.0.4”,“dotenv”: “^16.0.3”, “express”: “^4.18.2”, “mongodb”: “^4.13.0”, “node-modules”: “^1.0.1”, “router”: “^1.3.7”
import app from './server.js';
import ReviewsDAO from "./dao/reviewsDAO.js";
import mongodb from 'mongodb';
import dotenv from 'dotenv';
const MongoClient = mongodb.MongoClient
//Load the environment variables from the .env file
dotenv.config();
//Access the environment variables
const mongo_username = process.env.MONGO_USERNAME;
const mongo_password = process.env.MONGO_PASSWORD;
//access to the db
const url = new MongoClient(`mongodb+srv://${mongo_username}:${mongo_password}@cluster0.b5f7prn.mongodb.net/test`);
const port=4444;
MongoClient.connect(
url,
{
maxPoolSize: 50,
wtimeoutMS: 2500,
useNewUrlParser: true
})
.catch(err => {
console.error(err.stack)
process.exit(1)
})
.then(async client => {
await ReviewsDAO.injectDB(client)
app.listen(port, () => {
console.log(`listening on port ${port}`)
})
})