Home > OS >  ReferenceError: listDatabases is not defined at main (F:\MERN\server\app.js:20:5) at processTicks
ReferenceError: listDatabases is not defined at main (F:\MERN\server\app.js:20:5) at processTicks

Time:10-06

I was trying to connect mongodb to my backend or nodejs and got this error can anyone please help me in that

Note - I have changed the URL but due to security reasons I can't share it

this is nodejs code

const express = require("express");
const app = express("express");
const { MongoClient } = require("mongodb");

async function main() {
    const uri =
    "mongodb srv://puru:[email protected]/mernstack retryWrites=true&w=majority";

  const client = new MongoClient(uri);

  try {
    // Connect to the MongoDB cluster
    await client.connect();

    // Make the appropriate DB calls
    await listDatabases(client);
  } catch (e) {
    console.error(e);
  } finally {
    await client.close();
  }
}

main().catch(console.log("it didn't started            
  • Related