I encountered some errors in my project using Express.js and despite my attempts to fix them, I couldn't locate the source of the issue.
Below is a snippet of my code:
const mongodb = require("mongodb");
const dotenv = require("dotenv").config();
mongodb.connect(
process.env.CONNECTION,
{ useNewUrlParser: true, useUnifiedTopology: true },
function (err, client) {
if (err) {
console.log(err);
} else {
module.exports = client;
const app = require("./app");
app.listen(process.env.PORT, function () {
console.log("connected");
});
}
}
);
The error message I'm receiving is as follows:
Users/ismailtaibi/Documents/GitHub/worketplace-web/db.js:4 mongodb.connect( ^
TypeError: mongodb.connect is not a function at Object. (/Users/ismailtaibi/Documents/GitHub/worketplace-web/db.js:4:9) at Module._compile (internal/modules/cjs/loader.js:1072:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10) at Module.load (internal/modules/cjs/loader.js:937:32) at Function.Module._load (internal/modules/cjs/loader.js:778:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47