OneCompiler

Mysql with Node

134

dbConn = re
{dbConn} = re

common.js
const name = "Avinas1h";
data=[
{key:{'html_content':"<h1>hi i am ${name} </h1>"}}
]
data1=[
{key:{'html_content':"<h1>hi i am avinash</h1>"}}
]

exports.senj=()=>{

console.log("hihisenj",data[0].key)
}

//

const dbMongo = 'mongodb+srv://consoleavinash:[email protected]/?retryWrites=true&w=majority';

async function MongoDB() {
const client = new MongoClient(dbMongo, { useNewUrlParser: true, useUnifiedTopology: true });

try {
// Connect to the MongoDB server
await client.connect();
console.log('Connected to MongoDB');

// You can now perform operations on the database using the "client" object

// Example: List all databases
const databasesList = await client.db().admin().listDatabases();
console.log('Databases:', databasesList.databases.map(db => db.name));

} finally {
// Close the connection when finished
await client.close();
console.log('Disconnected from MongoDB');
}
}

// Call the function to connect to MongoDB
MongoDB();

module.exports = {dbConn,MongoDB};
///

const method_name = {"key2":"senj","key1":"getCountry1"};
  common[method_name.key2]();