I was minding my business until I stumble upon this TypeError. I tried my best to figure it out, but the codes won't work in my method.
const express = require("express");
const bodyParser = require("body-parser");
const mongoClient = require("mongodb").MongoClient;
const objectId = require("mongodb").ObjectID;
require("dotenv/config");
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended:true }));
app.get('/', (req, res) => {
app.listen(4000, () => {
console.log("It's connected to the server!");
mongoClient.connect(process.env.DB_CONNECTION, { useNewUrlParser:true, useUnifiedTopology: true }, (client, err) => {
if (err) {
throw error
};
const dB = client.db(process.env.DB_NAME); //Not a function, why?
dB.collection("cookie");
console.log(`Connected to "${process.env.DB_NAME}" !`);
});
});
I hope I get some good advice on how to tackle the problem properly. :)