Created
October 28, 2022 14:52
-
-
Save WoolDoughnut310/1a5fc6b6629cf9265a0149a35125e27e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Db, MongoClient } from "mongodb"; | |
const connectionString = process.env.ATLAS_URI; | |
const client = new MongoClient(connectionString); | |
let db: Db; | |
export const connectToServer = async () => { | |
await client.connect(); | |
db = client.db(process.env.DB_NAME); | |
console.log("Successfully connected to MongoDB."); | |
}; | |
const getDb = () => db; | |
export default getDb; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment