Skip to content

Instantly share code, notes, and snippets.

@WoolDoughnut310
Created October 28, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WoolDoughnut310/1a5fc6b6629cf9265a0149a35125e27e to your computer and use it in GitHub Desktop.
Save WoolDoughnut310/1a5fc6b6629cf9265a0149a35125e27e to your computer and use it in GitHub Desktop.
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