added express js
This commit is contained in:
20
db.js
Normal file
20
db.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { MongoClient } from "mongodb";
|
||||
|
||||
const client = new MongoClient(`mongodb://${process.env.MONGODB_USER}:${process.env.MONGODB_PASSWORD}@${process.env.MONGODB_URL}`);
|
||||
|
||||
const dbName = `jeopardy`;
|
||||
|
||||
/**
|
||||
* @type {Db}
|
||||
*/
|
||||
export let db;
|
||||
|
||||
export async function initDbConnection() {
|
||||
await client.connect();
|
||||
console.log('Connected successfully to mongodb');
|
||||
db = client.db(dbName);
|
||||
}
|
||||
|
||||
export function close() {
|
||||
client.close();
|
||||
}
|
||||
Reference in New Issue
Block a user